11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * sysctl.c: General linux system control interface 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Begun 24 March 1995, Stephen Tweedie 51da177e4SLinus Torvalds * Added /proc support, Dec 1995 61da177e4SLinus Torvalds * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas. 71da177e4SLinus Torvalds * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver. 81da177e4SLinus Torvalds * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver. 91da177e4SLinus Torvalds * Dynamic registration fixes, Stephen Tweedie. 101da177e4SLinus Torvalds * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn. 111da177e4SLinus Torvalds * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris 121da177e4SLinus Torvalds * Horn. 131da177e4SLinus Torvalds * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer. 141da177e4SLinus Torvalds * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer. 151da177e4SLinus Torvalds * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill 161da177e4SLinus Torvalds * Wendling. 171da177e4SLinus Torvalds * The list_for_each() macro wasn't appropriate for the sysctl loop. 181da177e4SLinus Torvalds * Removed it and replaced it with older style, 03/23/00, Bill Wendling 191da177e4SLinus Torvalds */ 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds #include <linux/module.h> 221da177e4SLinus Torvalds #include <linux/mm.h> 231da177e4SLinus Torvalds #include <linux/swap.h> 241da177e4SLinus Torvalds #include <linux/slab.h> 251da177e4SLinus Torvalds #include <linux/sysctl.h> 26d33ed52dSDave Young #include <linux/signal.h> 271da177e4SLinus Torvalds #include <linux/proc_fs.h> 2872c2d582SAndrew Morgan #include <linux/security.h> 291da177e4SLinus Torvalds #include <linux/ctype.h> 30dfec072eSVegard Nossum #include <linux/kmemcheck.h> 3162239ac2SAdrian Bunk #include <linux/fs.h> 321da177e4SLinus Torvalds #include <linux/init.h> 331da177e4SLinus Torvalds #include <linux/kernel.h> 340296b228SKay Sievers #include <linux/kobject.h> 3520380731SArnaldo Carvalho de Melo #include <linux/net.h> 361da177e4SLinus Torvalds #include <linux/sysrq.h> 371da177e4SLinus Torvalds #include <linux/highuid.h> 381da177e4SLinus Torvalds #include <linux/writeback.h> 393fff4c42SIngo Molnar #include <linux/ratelimit.h> 4076ab0f53SMel Gorman #include <linux/compaction.h> 411da177e4SLinus Torvalds #include <linux/hugetlb.h> 421da177e4SLinus Torvalds #include <linux/initrd.h> 430b77f5bfSDavid Howells #include <linux/key.h> 441da177e4SLinus Torvalds #include <linux/times.h> 451da177e4SLinus Torvalds #include <linux/limits.h> 461da177e4SLinus Torvalds #include <linux/dcache.h> 476e006701SAlexey Dobriyan #include <linux/dnotify.h> 481da177e4SLinus Torvalds #include <linux/syscalls.h> 49c748e134SAdrian Bunk #include <linux/vmstat.h> 50c255d844SPavel Machek #include <linux/nfs_fs.h> 51c255d844SPavel Machek #include <linux/acpi.h> 5210a0a8d4SJeremy Fitzhardinge #include <linux/reboot.h> 53b0fc494fSSteven Rostedt #include <linux/ftrace.h> 54cdd6c482SIngo Molnar #include <linux/perf_event.h> 55b2be84dfSMasami Hiramatsu #include <linux/kprobes.h> 56b492e95bSJens Axboe #include <linux/pipe_fs_i.h> 578e4228e1SDavid Rientjes #include <linux/oom.h> 581da177e4SLinus Torvalds 591da177e4SLinus Torvalds #include <asm/uaccess.h> 601da177e4SLinus Torvalds #include <asm/processor.h> 611da177e4SLinus Torvalds 6229cbc78bSAndi Kleen #ifdef CONFIG_X86 6329cbc78bSAndi Kleen #include <asm/nmi.h> 640741f4d2SChuck Ebbert #include <asm/stacktrace.h> 656e7c4025SIngo Molnar #include <asm/io.h> 6629cbc78bSAndi Kleen #endif 67c55b7c3eSDave Young #ifdef CONFIG_BSD_PROCESS_ACCT 68c55b7c3eSDave Young #include <linux/acct.h> 69c55b7c3eSDave Young #endif 704f0e056fSDave Young #ifdef CONFIG_RT_MUTEXES 714f0e056fSDave Young #include <linux/rtmutex.h> 724f0e056fSDave Young #endif 732edf5e49SDave Young #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT) 742edf5e49SDave Young #include <linux/lockdep.h> 752edf5e49SDave Young #endif 7615485a46SDave Young #ifdef CONFIG_CHR_DEV_SG 7715485a46SDave Young #include <scsi/sg.h> 7815485a46SDave Young #endif 7929cbc78bSAndi Kleen 8058687acbSDon Zickus #ifdef CONFIG_LOCKUP_DETECTOR 81504d7cf1SDon Zickus #include <linux/nmi.h> 82504d7cf1SDon Zickus #endif 83504d7cf1SDon Zickus 847058cb02SEric W. Biederman 851da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL) 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds /* External variables not in a header file. */ 881da177e4SLinus Torvalds extern int sysctl_overcommit_memory; 891da177e4SLinus Torvalds extern int sysctl_overcommit_ratio; 901da177e4SLinus Torvalds extern int max_threads; 911da177e4SLinus Torvalds extern int core_uses_pid; 92d6e71144SAlan Cox extern int suid_dumpable; 931da177e4SLinus Torvalds extern char core_pattern[]; 94a293980cSNeil Horman extern unsigned int core_pipe_limit; 951da177e4SLinus Torvalds extern int pid_max; 961da177e4SLinus Torvalds extern int min_free_kbytes; 971da177e4SLinus Torvalds extern int pid_max_min, pid_max_max; 989d0243bcSAndrew Morton extern int sysctl_drop_caches; 998ad4b1fbSRohit Seth extern int percpu_pagelist_fraction; 100bebfa101SAndi Kleen extern int compat_log; 1019745512cSArjan van de Ven extern int latencytop_enabled; 102eceea0b3SAl Viro extern int sysctl_nr_open_min, sysctl_nr_open_max; 103dd8632a1SPaul Mundt #ifndef CONFIG_MMU 104dd8632a1SPaul Mundt extern int sysctl_nr_trim_pages; 105dd8632a1SPaul Mundt #endif 106cb684b5bSJens Axboe #ifdef CONFIG_BLOCK 1075e605b64SJens Axboe extern int blk_iopoll_enabled; 108cb684b5bSJens Axboe #endif 1091da177e4SLinus Torvalds 110c4f3b63fSRavikiran G Thirumalai /* Constants used for minimum and maximum */ 1112508ce18SDon Zickus #ifdef CONFIG_LOCKUP_DETECTOR 112c4f3b63fSRavikiran G Thirumalai static int sixty = 60; 1139383d967SDimitri Sivanich static int neg_one = -1; 114c4f3b63fSRavikiran G Thirumalai #endif 115c4f3b63fSRavikiran G Thirumalai 116c4f3b63fSRavikiran G Thirumalai static int zero; 117cd5f9a4cSLinus Torvalds static int __maybe_unused one = 1; 118cd5f9a4cSLinus Torvalds static int __maybe_unused two = 2; 119fc3501d4SSven Wegener static unsigned long one_ul = 1; 120c4f3b63fSRavikiran G Thirumalai static int one_hundred = 100; 121af91322eSDave Young #ifdef CONFIG_PRINTK 122af91322eSDave Young static int ten_thousand = 10000; 123af91322eSDave Young #endif 124c4f3b63fSRavikiran G Thirumalai 1259e4a5bdaSAndrea Righi /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */ 1269e4a5bdaSAndrea Righi static unsigned long dirty_bytes_min = 2 * PAGE_SIZE; 1279e4a5bdaSAndrea Righi 1281da177e4SLinus Torvalds /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */ 1291da177e4SLinus Torvalds static int maxolduid = 65535; 1301da177e4SLinus Torvalds static int minolduid; 1318ad4b1fbSRohit Seth static int min_percpu_pagelist_fract = 8; 1321da177e4SLinus Torvalds 1331da177e4SLinus Torvalds static int ngroups_max = NGROUPS_MAX; 1341da177e4SLinus Torvalds 135d14f1729SDave Young #ifdef CONFIG_INOTIFY_USER 136d14f1729SDave Young #include <linux/inotify.h> 137d14f1729SDave Young #endif 13872c57ed5SDavid S. Miller #ifdef CONFIG_SPARC 13917f04fbbSDavid S. Miller #include <asm/system.h> 1401da177e4SLinus Torvalds #endif 1411da177e4SLinus Torvalds 1420871420fSDavid S. Miller #ifdef CONFIG_SPARC64 1430871420fSDavid S. Miller extern int sysctl_tsb_ratio; 1440871420fSDavid S. Miller #endif 1450871420fSDavid S. Miller 1461da177e4SLinus Torvalds #ifdef __hppa__ 1471da177e4SLinus Torvalds extern int pwrsw_enabled; 1481da177e4SLinus Torvalds extern int unaligned_enabled; 1491da177e4SLinus Torvalds #endif 1501da177e4SLinus Torvalds 151347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390 1521da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU 1531da177e4SLinus Torvalds extern int sysctl_ieee_emulation_warnings; 1541da177e4SLinus Torvalds #endif 1551da177e4SLinus Torvalds extern int sysctl_userprocess_debug; 156951f22d5SMartin Schwidefsky extern int spin_retry; 1571da177e4SLinus Torvalds #endif 1581da177e4SLinus Torvalds 159d2b176edSJes Sorensen #ifdef CONFIG_IA64 160d2b176edSJes Sorensen extern int no_unaligned_warning; 16188fc241fSDoug Chapman extern int unaligned_dump_stack; 162d2b176edSJes Sorensen #endif 163d2b176edSJes Sorensen 164d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL 1658d65af78SAlexey Dobriyan static int proc_do_cad_pid(struct ctl_table *table, int write, 1669ec52099SCedric Le Goater void __user *buffer, size_t *lenp, loff_t *ppos); 1678d65af78SAlexey Dobriyan static int proc_taint(struct ctl_table *table, int write, 16834f5a398STheodore Ts'o void __user *buffer, size_t *lenp, loff_t *ppos); 169d6f8ff73SRandy Dunlap #endif 1709ec52099SCedric Le Goater 17197f5f0cdSDmitry Torokhov #ifdef CONFIG_MAGIC_SYSRQ 17297f5f0cdSDmitry Torokhov static int __sysrq_enabled; /* Note: sysrq code ises it's own private copy */ 17397f5f0cdSDmitry Torokhov 17497f5f0cdSDmitry Torokhov static int sysrq_sysctl_handler(ctl_table *table, int write, 17597f5f0cdSDmitry Torokhov void __user *buffer, size_t *lenp, 17697f5f0cdSDmitry Torokhov loff_t *ppos) 17797f5f0cdSDmitry Torokhov { 17897f5f0cdSDmitry Torokhov int error; 17997f5f0cdSDmitry Torokhov 18097f5f0cdSDmitry Torokhov error = proc_dointvec(table, write, buffer, lenp, ppos); 18197f5f0cdSDmitry Torokhov if (error) 18297f5f0cdSDmitry Torokhov return error; 18397f5f0cdSDmitry Torokhov 18497f5f0cdSDmitry Torokhov if (write) 18597f5f0cdSDmitry Torokhov sysrq_toggle_support(__sysrq_enabled); 18697f5f0cdSDmitry Torokhov 18797f5f0cdSDmitry Torokhov return 0; 18897f5f0cdSDmitry Torokhov } 18997f5f0cdSDmitry Torokhov 19097f5f0cdSDmitry Torokhov #endif 19197f5f0cdSDmitry Torokhov 192d8217f07SEric W. Biederman static struct ctl_table root_table[]; 193e51b6ba0SEric W. Biederman static struct ctl_table_root sysctl_table_root; 194e51b6ba0SEric W. Biederman static struct ctl_table_header root_table_header = { 195b380b0d4SAl Viro .count = 1, 196e51b6ba0SEric W. Biederman .ctl_table = root_table, 19773455092SAl Viro .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list), 198e51b6ba0SEric W. Biederman .root = &sysctl_table_root, 19973455092SAl Viro .set = &sysctl_table_root.default_set, 200e51b6ba0SEric W. Biederman }; 201e51b6ba0SEric W. Biederman static struct ctl_table_root sysctl_table_root = { 202e51b6ba0SEric W. Biederman .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list), 20373455092SAl Viro .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry), 204e51b6ba0SEric W. Biederman }; 2051da177e4SLinus Torvalds 206d8217f07SEric W. Biederman static struct ctl_table kern_table[]; 207d8217f07SEric W. Biederman static struct ctl_table vm_table[]; 208d8217f07SEric W. Biederman static struct ctl_table fs_table[]; 209d8217f07SEric W. Biederman static struct ctl_table debug_table[]; 210d8217f07SEric W. Biederman static struct ctl_table dev_table[]; 211d8217f07SEric W. Biederman extern struct ctl_table random_table[]; 2127ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL 2137ef9964eSDavide Libenzi extern struct ctl_table epoll_table[]; 2147ef9964eSDavide Libenzi #endif 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT 2171da177e4SLinus Torvalds int sysctl_legacy_va_layout; 2181da177e4SLinus Torvalds #endif 2191da177e4SLinus Torvalds 2201da177e4SLinus Torvalds /* The default sysctl tables: */ 2211da177e4SLinus Torvalds 222d8217f07SEric W. Biederman static struct ctl_table root_table[] = { 2231da177e4SLinus Torvalds { 2241da177e4SLinus Torvalds .procname = "kernel", 2251da177e4SLinus Torvalds .mode = 0555, 2261da177e4SLinus Torvalds .child = kern_table, 2271da177e4SLinus Torvalds }, 2281da177e4SLinus Torvalds { 2291da177e4SLinus Torvalds .procname = "vm", 2301da177e4SLinus Torvalds .mode = 0555, 2311da177e4SLinus Torvalds .child = vm_table, 2321da177e4SLinus Torvalds }, 2331da177e4SLinus Torvalds { 2341da177e4SLinus Torvalds .procname = "fs", 2351da177e4SLinus Torvalds .mode = 0555, 2361da177e4SLinus Torvalds .child = fs_table, 2371da177e4SLinus Torvalds }, 2381da177e4SLinus Torvalds { 2391da177e4SLinus Torvalds .procname = "debug", 2401da177e4SLinus Torvalds .mode = 0555, 2411da177e4SLinus Torvalds .child = debug_table, 2421da177e4SLinus Torvalds }, 2431da177e4SLinus Torvalds { 2441da177e4SLinus Torvalds .procname = "dev", 2451da177e4SLinus Torvalds .mode = 0555, 2461da177e4SLinus Torvalds .child = dev_table, 2471da177e4SLinus Torvalds }, 2482be7fe07SAndrew Morton /* 2492be7fe07SAndrew Morton * NOTE: do not add new entries to this table unless you have read 2502be7fe07SAndrew Morton * Documentation/sysctl/ctl_unnumbered.txt 2512be7fe07SAndrew Morton */ 2526fce56ecSEric W. Biederman { } 2531da177e4SLinus Torvalds }; 2541da177e4SLinus Torvalds 25577e54a1fSIngo Molnar #ifdef CONFIG_SCHED_DEBUG 25673c4efd2SEric Dumazet static int min_sched_granularity_ns = 100000; /* 100 usecs */ 25773c4efd2SEric Dumazet static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */ 25873c4efd2SEric Dumazet static int min_wakeup_granularity_ns; /* 0 usecs */ 25973c4efd2SEric Dumazet static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */ 2601983a922SChristian Ehrhardt static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE; 2611983a922SChristian Ehrhardt static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1; 26277e54a1fSIngo Molnar #endif 26377e54a1fSIngo Molnar 2645e771905SMel Gorman #ifdef CONFIG_COMPACTION 2655e771905SMel Gorman static int min_extfrag_threshold; 2665e771905SMel Gorman static int max_extfrag_threshold = 1000; 2675e771905SMel Gorman #endif 2685e771905SMel Gorman 269d8217f07SEric W. Biederman static struct ctl_table kern_table[] = { 2702bba22c5SMike Galbraith { 2712bba22c5SMike Galbraith .procname = "sched_child_runs_first", 2722bba22c5SMike Galbraith .data = &sysctl_sched_child_runs_first, 2732bba22c5SMike Galbraith .maxlen = sizeof(unsigned int), 2742bba22c5SMike Galbraith .mode = 0644, 2756d456111SEric W. Biederman .proc_handler = proc_dointvec, 2762bba22c5SMike Galbraith }, 27777e54a1fSIngo Molnar #ifdef CONFIG_SCHED_DEBUG 27877e54a1fSIngo Molnar { 279b2be5e96SPeter Zijlstra .procname = "sched_min_granularity_ns", 280b2be5e96SPeter Zijlstra .data = &sysctl_sched_min_granularity, 28177e54a1fSIngo Molnar .maxlen = sizeof(unsigned int), 28277e54a1fSIngo Molnar .mode = 0644, 283702a7c76SLinus Torvalds .proc_handler = sched_proc_update_handler, 284b2be5e96SPeter Zijlstra .extra1 = &min_sched_granularity_ns, 285b2be5e96SPeter Zijlstra .extra2 = &max_sched_granularity_ns, 28677e54a1fSIngo Molnar }, 28777e54a1fSIngo Molnar { 28821805085SPeter Zijlstra .procname = "sched_latency_ns", 28921805085SPeter Zijlstra .data = &sysctl_sched_latency, 29021805085SPeter Zijlstra .maxlen = sizeof(unsigned int), 29121805085SPeter Zijlstra .mode = 0644, 292702a7c76SLinus Torvalds .proc_handler = sched_proc_update_handler, 29321805085SPeter Zijlstra .extra1 = &min_sched_granularity_ns, 29421805085SPeter Zijlstra .extra2 = &max_sched_granularity_ns, 29521805085SPeter Zijlstra }, 29621805085SPeter Zijlstra { 29777e54a1fSIngo Molnar .procname = "sched_wakeup_granularity_ns", 29877e54a1fSIngo Molnar .data = &sysctl_sched_wakeup_granularity, 29977e54a1fSIngo Molnar .maxlen = sizeof(unsigned int), 30077e54a1fSIngo Molnar .mode = 0644, 301702a7c76SLinus Torvalds .proc_handler = sched_proc_update_handler, 30277e54a1fSIngo Molnar .extra1 = &min_wakeup_granularity_ns, 30377e54a1fSIngo Molnar .extra2 = &max_wakeup_granularity_ns, 30477e54a1fSIngo Molnar }, 30577e54a1fSIngo Molnar { 3061983a922SChristian Ehrhardt .procname = "sched_tunable_scaling", 3071983a922SChristian Ehrhardt .data = &sysctl_sched_tunable_scaling, 3081983a922SChristian Ehrhardt .maxlen = sizeof(enum sched_tunable_scaling), 3091983a922SChristian Ehrhardt .mode = 0644, 310702a7c76SLinus Torvalds .proc_handler = sched_proc_update_handler, 3111983a922SChristian Ehrhardt .extra1 = &min_sched_tunable_scaling, 3121983a922SChristian Ehrhardt .extra2 = &max_sched_tunable_scaling, 3132398f2c6SPeter Zijlstra }, 3142398f2c6SPeter Zijlstra { 315da84d961SIngo Molnar .procname = "sched_migration_cost", 316da84d961SIngo Molnar .data = &sysctl_sched_migration_cost, 317da84d961SIngo Molnar .maxlen = sizeof(unsigned int), 318da84d961SIngo Molnar .mode = 0644, 3196d456111SEric W. Biederman .proc_handler = proc_dointvec, 320da84d961SIngo Molnar }, 321b82d9fddSPeter Zijlstra { 322b82d9fddSPeter Zijlstra .procname = "sched_nr_migrate", 323b82d9fddSPeter Zijlstra .data = &sysctl_sched_nr_migrate, 324b82d9fddSPeter Zijlstra .maxlen = sizeof(unsigned int), 325fa85ae24SPeter Zijlstra .mode = 0644, 3266d456111SEric W. Biederman .proc_handler = proc_dointvec, 327fa85ae24SPeter Zijlstra }, 328cd1bb94bSArun R Bharadwaj { 329e9e9250bSPeter Zijlstra .procname = "sched_time_avg", 330e9e9250bSPeter Zijlstra .data = &sysctl_sched_time_avg, 331e9e9250bSPeter Zijlstra .maxlen = sizeof(unsigned int), 332e9e9250bSPeter Zijlstra .mode = 0644, 3336d456111SEric W. Biederman .proc_handler = proc_dointvec, 334e9e9250bSPeter Zijlstra }, 335e9e9250bSPeter Zijlstra { 336*a7a4f8a7SPaul Turner .procname = "sched_shares_window", 337*a7a4f8a7SPaul Turner .data = &sysctl_sched_shares_window, 338*a7a4f8a7SPaul Turner .maxlen = sizeof(unsigned int), 339*a7a4f8a7SPaul Turner .mode = 0644, 340*a7a4f8a7SPaul Turner .proc_handler = proc_dointvec, 341*a7a4f8a7SPaul Turner }, 342*a7a4f8a7SPaul Turner { 343cd1bb94bSArun R Bharadwaj .procname = "timer_migration", 344cd1bb94bSArun R Bharadwaj .data = &sysctl_timer_migration, 345cd1bb94bSArun R Bharadwaj .maxlen = sizeof(unsigned int), 346cd1bb94bSArun R Bharadwaj .mode = 0644, 3476d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 348bfdb4d9fSArun R Bharadwaj .extra1 = &zero, 349bfdb4d9fSArun R Bharadwaj .extra2 = &one, 350cd1bb94bSArun R Bharadwaj }, 3511fc84aaaSPeter Zijlstra #endif 3521799e35dSIngo Molnar { 3539f0c1e56SPeter Zijlstra .procname = "sched_rt_period_us", 3549f0c1e56SPeter Zijlstra .data = &sysctl_sched_rt_period, 3559f0c1e56SPeter Zijlstra .maxlen = sizeof(unsigned int), 3569f0c1e56SPeter Zijlstra .mode = 0644, 3576d456111SEric W. Biederman .proc_handler = sched_rt_handler, 3589f0c1e56SPeter Zijlstra }, 3599f0c1e56SPeter Zijlstra { 3609f0c1e56SPeter Zijlstra .procname = "sched_rt_runtime_us", 3619f0c1e56SPeter Zijlstra .data = &sysctl_sched_rt_runtime, 3629f0c1e56SPeter Zijlstra .maxlen = sizeof(int), 3639f0c1e56SPeter Zijlstra .mode = 0644, 3646d456111SEric W. Biederman .proc_handler = sched_rt_handler, 3659f0c1e56SPeter Zijlstra }, 3669f0c1e56SPeter Zijlstra { 3671799e35dSIngo Molnar .procname = "sched_compat_yield", 3681799e35dSIngo Molnar .data = &sysctl_sched_compat_yield, 3691799e35dSIngo Molnar .maxlen = sizeof(unsigned int), 3701799e35dSIngo Molnar .mode = 0644, 3716d456111SEric W. Biederman .proc_handler = proc_dointvec, 3721799e35dSIngo Molnar }, 373f20786ffSPeter Zijlstra #ifdef CONFIG_PROVE_LOCKING 374f20786ffSPeter Zijlstra { 375f20786ffSPeter Zijlstra .procname = "prove_locking", 376f20786ffSPeter Zijlstra .data = &prove_locking, 377f20786ffSPeter Zijlstra .maxlen = sizeof(int), 378f20786ffSPeter Zijlstra .mode = 0644, 3796d456111SEric W. Biederman .proc_handler = proc_dointvec, 380f20786ffSPeter Zijlstra }, 381f20786ffSPeter Zijlstra #endif 382f20786ffSPeter Zijlstra #ifdef CONFIG_LOCK_STAT 383f20786ffSPeter Zijlstra { 384f20786ffSPeter Zijlstra .procname = "lock_stat", 385f20786ffSPeter Zijlstra .data = &lock_stat, 386f20786ffSPeter Zijlstra .maxlen = sizeof(int), 387f20786ffSPeter Zijlstra .mode = 0644, 3886d456111SEric W. Biederman .proc_handler = proc_dointvec, 389f20786ffSPeter Zijlstra }, 390f20786ffSPeter Zijlstra #endif 39177e54a1fSIngo Molnar { 3921da177e4SLinus Torvalds .procname = "panic", 3931da177e4SLinus Torvalds .data = &panic_timeout, 3941da177e4SLinus Torvalds .maxlen = sizeof(int), 3951da177e4SLinus Torvalds .mode = 0644, 3966d456111SEric W. Biederman .proc_handler = proc_dointvec, 3971da177e4SLinus Torvalds }, 3981da177e4SLinus Torvalds { 3991da177e4SLinus Torvalds .procname = "core_uses_pid", 4001da177e4SLinus Torvalds .data = &core_uses_pid, 4011da177e4SLinus Torvalds .maxlen = sizeof(int), 4021da177e4SLinus Torvalds .mode = 0644, 4036d456111SEric W. Biederman .proc_handler = proc_dointvec, 4041da177e4SLinus Torvalds }, 4051da177e4SLinus Torvalds { 4061da177e4SLinus Torvalds .procname = "core_pattern", 4071da177e4SLinus Torvalds .data = core_pattern, 40871ce92f3SDan Aloni .maxlen = CORENAME_MAX_SIZE, 4091da177e4SLinus Torvalds .mode = 0644, 4106d456111SEric W. Biederman .proc_handler = proc_dostring, 4111da177e4SLinus Torvalds }, 412a293980cSNeil Horman { 413a293980cSNeil Horman .procname = "core_pipe_limit", 414a293980cSNeil Horman .data = &core_pipe_limit, 415a293980cSNeil Horman .maxlen = sizeof(unsigned int), 416a293980cSNeil Horman .mode = 0644, 4176d456111SEric W. Biederman .proc_handler = proc_dointvec, 418a293980cSNeil Horman }, 41934f5a398STheodore Ts'o #ifdef CONFIG_PROC_SYSCTL 4201da177e4SLinus Torvalds { 4211da177e4SLinus Torvalds .procname = "tainted", 42225ddbb18SAndi Kleen .maxlen = sizeof(long), 42334f5a398STheodore Ts'o .mode = 0644, 4246d456111SEric W. Biederman .proc_handler = proc_taint, 4251da177e4SLinus Torvalds }, 42634f5a398STheodore Ts'o #endif 4279745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP 4289745512cSArjan van de Ven { 4299745512cSArjan van de Ven .procname = "latencytop", 4309745512cSArjan van de Ven .data = &latencytop_enabled, 4319745512cSArjan van de Ven .maxlen = sizeof(int), 4329745512cSArjan van de Ven .mode = 0644, 4336d456111SEric W. Biederman .proc_handler = proc_dointvec, 4349745512cSArjan van de Ven }, 4359745512cSArjan van de Ven #endif 4361da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD 4371da177e4SLinus Torvalds { 4381da177e4SLinus Torvalds .procname = "real-root-dev", 4391da177e4SLinus Torvalds .data = &real_root_dev, 4401da177e4SLinus Torvalds .maxlen = sizeof(int), 4411da177e4SLinus Torvalds .mode = 0644, 4426d456111SEric W. Biederman .proc_handler = proc_dointvec, 4431da177e4SLinus Torvalds }, 4441da177e4SLinus Torvalds #endif 44545807a1dSIngo Molnar { 44645807a1dSIngo Molnar .procname = "print-fatal-signals", 44745807a1dSIngo Molnar .data = &print_fatal_signals, 44845807a1dSIngo Molnar .maxlen = sizeof(int), 44945807a1dSIngo Molnar .mode = 0644, 4506d456111SEric W. Biederman .proc_handler = proc_dointvec, 45145807a1dSIngo Molnar }, 45272c57ed5SDavid S. Miller #ifdef CONFIG_SPARC 4531da177e4SLinus Torvalds { 4541da177e4SLinus Torvalds .procname = "reboot-cmd", 4551da177e4SLinus Torvalds .data = reboot_command, 4561da177e4SLinus Torvalds .maxlen = 256, 4571da177e4SLinus Torvalds .mode = 0644, 4586d456111SEric W. Biederman .proc_handler = proc_dostring, 4591da177e4SLinus Torvalds }, 4601da177e4SLinus Torvalds { 4611da177e4SLinus Torvalds .procname = "stop-a", 4621da177e4SLinus Torvalds .data = &stop_a_enabled, 4631da177e4SLinus Torvalds .maxlen = sizeof (int), 4641da177e4SLinus Torvalds .mode = 0644, 4656d456111SEric W. Biederman .proc_handler = proc_dointvec, 4661da177e4SLinus Torvalds }, 4671da177e4SLinus Torvalds { 4681da177e4SLinus Torvalds .procname = "scons-poweroff", 4691da177e4SLinus Torvalds .data = &scons_pwroff, 4701da177e4SLinus Torvalds .maxlen = sizeof (int), 4711da177e4SLinus Torvalds .mode = 0644, 4726d456111SEric W. Biederman .proc_handler = proc_dointvec, 4731da177e4SLinus Torvalds }, 4741da177e4SLinus Torvalds #endif 4750871420fSDavid S. Miller #ifdef CONFIG_SPARC64 4760871420fSDavid S. Miller { 4770871420fSDavid S. Miller .procname = "tsb-ratio", 4780871420fSDavid S. Miller .data = &sysctl_tsb_ratio, 4790871420fSDavid S. Miller .maxlen = sizeof (int), 4800871420fSDavid S. Miller .mode = 0644, 4816d456111SEric W. Biederman .proc_handler = proc_dointvec, 4820871420fSDavid S. Miller }, 4830871420fSDavid S. Miller #endif 4841da177e4SLinus Torvalds #ifdef __hppa__ 4851da177e4SLinus Torvalds { 4861da177e4SLinus Torvalds .procname = "soft-power", 4871da177e4SLinus Torvalds .data = &pwrsw_enabled, 4881da177e4SLinus Torvalds .maxlen = sizeof (int), 4891da177e4SLinus Torvalds .mode = 0644, 4906d456111SEric W. Biederman .proc_handler = proc_dointvec, 4911da177e4SLinus Torvalds }, 4921da177e4SLinus Torvalds { 4931da177e4SLinus Torvalds .procname = "unaligned-trap", 4941da177e4SLinus Torvalds .data = &unaligned_enabled, 4951da177e4SLinus Torvalds .maxlen = sizeof (int), 4961da177e4SLinus Torvalds .mode = 0644, 4976d456111SEric W. Biederman .proc_handler = proc_dointvec, 4981da177e4SLinus Torvalds }, 4991da177e4SLinus Torvalds #endif 5001da177e4SLinus Torvalds { 5011da177e4SLinus Torvalds .procname = "ctrl-alt-del", 5021da177e4SLinus Torvalds .data = &C_A_D, 5031da177e4SLinus Torvalds .maxlen = sizeof(int), 5041da177e4SLinus Torvalds .mode = 0644, 5056d456111SEric W. Biederman .proc_handler = proc_dointvec, 5061da177e4SLinus Torvalds }, 507606576ceSSteven Rostedt #ifdef CONFIG_FUNCTION_TRACER 508b0fc494fSSteven Rostedt { 509b0fc494fSSteven Rostedt .procname = "ftrace_enabled", 510b0fc494fSSteven Rostedt .data = &ftrace_enabled, 511b0fc494fSSteven Rostedt .maxlen = sizeof(int), 512b0fc494fSSteven Rostedt .mode = 0644, 5136d456111SEric W. Biederman .proc_handler = ftrace_enable_sysctl, 514b0fc494fSSteven Rostedt }, 515b0fc494fSSteven Rostedt #endif 516f38f1d2aSSteven Rostedt #ifdef CONFIG_STACK_TRACER 517f38f1d2aSSteven Rostedt { 518f38f1d2aSSteven Rostedt .procname = "stack_tracer_enabled", 519f38f1d2aSSteven Rostedt .data = &stack_tracer_enabled, 520f38f1d2aSSteven Rostedt .maxlen = sizeof(int), 521f38f1d2aSSteven Rostedt .mode = 0644, 5226d456111SEric W. Biederman .proc_handler = stack_trace_sysctl, 523f38f1d2aSSteven Rostedt }, 524f38f1d2aSSteven Rostedt #endif 525944ac425SSteven Rostedt #ifdef CONFIG_TRACING 526944ac425SSteven Rostedt { 5273299b4ddSPeter Zijlstra .procname = "ftrace_dump_on_oops", 528944ac425SSteven Rostedt .data = &ftrace_dump_on_oops, 529944ac425SSteven Rostedt .maxlen = sizeof(int), 530944ac425SSteven Rostedt .mode = 0644, 5316d456111SEric W. Biederman .proc_handler = proc_dointvec, 532944ac425SSteven Rostedt }, 533944ac425SSteven Rostedt #endif 534a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES 5351da177e4SLinus Torvalds { 5361da177e4SLinus Torvalds .procname = "modprobe", 5371da177e4SLinus Torvalds .data = &modprobe_path, 5381da177e4SLinus Torvalds .maxlen = KMOD_PATH_LEN, 5391da177e4SLinus Torvalds .mode = 0644, 5406d456111SEric W. Biederman .proc_handler = proc_dostring, 5411da177e4SLinus Torvalds }, 5423d43321bSKees Cook { 5433d43321bSKees Cook .procname = "modules_disabled", 5443d43321bSKees Cook .data = &modules_disabled, 5453d43321bSKees Cook .maxlen = sizeof(int), 5463d43321bSKees Cook .mode = 0644, 5473d43321bSKees Cook /* only handle a transition from default "0" to "1" */ 5486d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 5493d43321bSKees Cook .extra1 = &one, 5503d43321bSKees Cook .extra2 = &one, 5513d43321bSKees Cook }, 5521da177e4SLinus Torvalds #endif 55394f17cd7SIan Abbott #ifdef CONFIG_HOTPLUG 5541da177e4SLinus Torvalds { 5551da177e4SLinus Torvalds .procname = "hotplug", 556312c004dSKay Sievers .data = &uevent_helper, 557312c004dSKay Sievers .maxlen = UEVENT_HELPER_PATH_LEN, 5581da177e4SLinus Torvalds .mode = 0644, 5596d456111SEric W. Biederman .proc_handler = proc_dostring, 5601da177e4SLinus Torvalds }, 5611da177e4SLinus Torvalds #endif 5621da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG 5631da177e4SLinus Torvalds { 5641da177e4SLinus Torvalds .procname = "sg-big-buff", 5651da177e4SLinus Torvalds .data = &sg_big_buff, 5661da177e4SLinus Torvalds .maxlen = sizeof (int), 5671da177e4SLinus Torvalds .mode = 0444, 5686d456111SEric W. Biederman .proc_handler = proc_dointvec, 5691da177e4SLinus Torvalds }, 5701da177e4SLinus Torvalds #endif 5711da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT 5721da177e4SLinus Torvalds { 5731da177e4SLinus Torvalds .procname = "acct", 5741da177e4SLinus Torvalds .data = &acct_parm, 5751da177e4SLinus Torvalds .maxlen = 3*sizeof(int), 5761da177e4SLinus Torvalds .mode = 0644, 5776d456111SEric W. Biederman .proc_handler = proc_dointvec, 5781da177e4SLinus Torvalds }, 5791da177e4SLinus Torvalds #endif 5801da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ 5811da177e4SLinus Torvalds { 5821da177e4SLinus Torvalds .procname = "sysrq", 5835d6f647fSIngo Molnar .data = &__sysrq_enabled, 5841da177e4SLinus Torvalds .maxlen = sizeof (int), 5851da177e4SLinus Torvalds .mode = 0644, 58697f5f0cdSDmitry Torokhov .proc_handler = sysrq_sysctl_handler, 5871da177e4SLinus Torvalds }, 5881da177e4SLinus Torvalds #endif 589d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL 5901da177e4SLinus Torvalds { 5911da177e4SLinus Torvalds .procname = "cad_pid", 5929ec52099SCedric Le Goater .data = NULL, 5931da177e4SLinus Torvalds .maxlen = sizeof (int), 5941da177e4SLinus Torvalds .mode = 0600, 5956d456111SEric W. Biederman .proc_handler = proc_do_cad_pid, 5961da177e4SLinus Torvalds }, 597d6f8ff73SRandy Dunlap #endif 5981da177e4SLinus Torvalds { 5991da177e4SLinus Torvalds .procname = "threads-max", 6001da177e4SLinus Torvalds .data = &max_threads, 6011da177e4SLinus Torvalds .maxlen = sizeof(int), 6021da177e4SLinus Torvalds .mode = 0644, 6036d456111SEric W. Biederman .proc_handler = proc_dointvec, 6041da177e4SLinus Torvalds }, 6051da177e4SLinus Torvalds { 6061da177e4SLinus Torvalds .procname = "random", 6071da177e4SLinus Torvalds .mode = 0555, 6081da177e4SLinus Torvalds .child = random_table, 6091da177e4SLinus Torvalds }, 6101da177e4SLinus Torvalds { 6111da177e4SLinus Torvalds .procname = "overflowuid", 6121da177e4SLinus Torvalds .data = &overflowuid, 6131da177e4SLinus Torvalds .maxlen = sizeof(int), 6141da177e4SLinus Torvalds .mode = 0644, 6156d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 6161da177e4SLinus Torvalds .extra1 = &minolduid, 6171da177e4SLinus Torvalds .extra2 = &maxolduid, 6181da177e4SLinus Torvalds }, 6191da177e4SLinus Torvalds { 6201da177e4SLinus Torvalds .procname = "overflowgid", 6211da177e4SLinus Torvalds .data = &overflowgid, 6221da177e4SLinus Torvalds .maxlen = sizeof(int), 6231da177e4SLinus Torvalds .mode = 0644, 6246d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 6251da177e4SLinus Torvalds .extra1 = &minolduid, 6261da177e4SLinus Torvalds .extra2 = &maxolduid, 6271da177e4SLinus Torvalds }, 628347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390 6291da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU 6301da177e4SLinus Torvalds { 6311da177e4SLinus Torvalds .procname = "ieee_emulation_warnings", 6321da177e4SLinus Torvalds .data = &sysctl_ieee_emulation_warnings, 6331da177e4SLinus Torvalds .maxlen = sizeof(int), 6341da177e4SLinus Torvalds .mode = 0644, 6356d456111SEric W. Biederman .proc_handler = proc_dointvec, 6361da177e4SLinus Torvalds }, 6371da177e4SLinus Torvalds #endif 6381da177e4SLinus Torvalds { 6391da177e4SLinus Torvalds .procname = "userprocess_debug", 640ab3c68eeSHeiko Carstens .data = &show_unhandled_signals, 6411da177e4SLinus Torvalds .maxlen = sizeof(int), 6421da177e4SLinus Torvalds .mode = 0644, 6436d456111SEric W. Biederman .proc_handler = proc_dointvec, 6441da177e4SLinus Torvalds }, 6451da177e4SLinus Torvalds #endif 6461da177e4SLinus Torvalds { 6471da177e4SLinus Torvalds .procname = "pid_max", 6481da177e4SLinus Torvalds .data = &pid_max, 6491da177e4SLinus Torvalds .maxlen = sizeof (int), 6501da177e4SLinus Torvalds .mode = 0644, 6516d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 6521da177e4SLinus Torvalds .extra1 = &pid_max_min, 6531da177e4SLinus Torvalds .extra2 = &pid_max_max, 6541da177e4SLinus Torvalds }, 6551da177e4SLinus Torvalds { 6561da177e4SLinus Torvalds .procname = "panic_on_oops", 6571da177e4SLinus Torvalds .data = &panic_on_oops, 6581da177e4SLinus Torvalds .maxlen = sizeof(int), 6591da177e4SLinus Torvalds .mode = 0644, 6606d456111SEric W. Biederman .proc_handler = proc_dointvec, 6611da177e4SLinus Torvalds }, 6627ef3d2fdSJoe Perches #if defined CONFIG_PRINTK 6637ef3d2fdSJoe Perches { 6647ef3d2fdSJoe Perches .procname = "printk", 6657ef3d2fdSJoe Perches .data = &console_loglevel, 6667ef3d2fdSJoe Perches .maxlen = 4*sizeof(int), 6677ef3d2fdSJoe Perches .mode = 0644, 6686d456111SEric W. Biederman .proc_handler = proc_dointvec, 6697ef3d2fdSJoe Perches }, 6701da177e4SLinus Torvalds { 6711da177e4SLinus Torvalds .procname = "printk_ratelimit", 672717115e1SDave Young .data = &printk_ratelimit_state.interval, 6731da177e4SLinus Torvalds .maxlen = sizeof(int), 6741da177e4SLinus Torvalds .mode = 0644, 6756d456111SEric W. Biederman .proc_handler = proc_dointvec_jiffies, 6761da177e4SLinus Torvalds }, 6771da177e4SLinus Torvalds { 6781da177e4SLinus Torvalds .procname = "printk_ratelimit_burst", 679717115e1SDave Young .data = &printk_ratelimit_state.burst, 6801da177e4SLinus Torvalds .maxlen = sizeof(int), 6811da177e4SLinus Torvalds .mode = 0644, 6826d456111SEric W. Biederman .proc_handler = proc_dointvec, 6831da177e4SLinus Torvalds }, 684af91322eSDave Young { 685af91322eSDave Young .procname = "printk_delay", 686af91322eSDave Young .data = &printk_delay_msec, 687af91322eSDave Young .maxlen = sizeof(int), 688af91322eSDave Young .mode = 0644, 6896d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 690af91322eSDave Young .extra1 = &zero, 691af91322eSDave Young .extra2 = &ten_thousand, 692af91322eSDave Young }, 6937ef3d2fdSJoe Perches #endif 6941da177e4SLinus Torvalds { 695eaf06b24SDan Rosenberg .procname = "dmesg_restrict", 696eaf06b24SDan Rosenberg .data = &dmesg_restrict, 697eaf06b24SDan Rosenberg .maxlen = sizeof(int), 698eaf06b24SDan Rosenberg .mode = 0644, 699eaf06b24SDan Rosenberg .proc_handler = proc_dointvec_minmax, 700eaf06b24SDan Rosenberg .extra1 = &zero, 701eaf06b24SDan Rosenberg .extra2 = &one, 702eaf06b24SDan Rosenberg }, 703eaf06b24SDan Rosenberg { 7041da177e4SLinus Torvalds .procname = "ngroups_max", 7051da177e4SLinus Torvalds .data = &ngroups_max, 7061da177e4SLinus Torvalds .maxlen = sizeof (int), 7071da177e4SLinus Torvalds .mode = 0444, 7086d456111SEric W. Biederman .proc_handler = proc_dointvec, 7091da177e4SLinus Torvalds }, 71058687acbSDon Zickus #if defined(CONFIG_LOCKUP_DETECTOR) 711504d7cf1SDon Zickus { 71258687acbSDon Zickus .procname = "watchdog", 71358687acbSDon Zickus .data = &watchdog_enabled, 714504d7cf1SDon Zickus .maxlen = sizeof (int), 715504d7cf1SDon Zickus .mode = 0644, 71658687acbSDon Zickus .proc_handler = proc_dowatchdog_enabled, 71758687acbSDon Zickus }, 71858687acbSDon Zickus { 71958687acbSDon Zickus .procname = "watchdog_thresh", 72058687acbSDon Zickus .data = &softlockup_thresh, 72158687acbSDon Zickus .maxlen = sizeof(int), 72258687acbSDon Zickus .mode = 0644, 72358687acbSDon Zickus .proc_handler = proc_dowatchdog_thresh, 72458687acbSDon Zickus .extra1 = &neg_one, 72558687acbSDon Zickus .extra2 = &sixty, 726504d7cf1SDon Zickus }, 7272508ce18SDon Zickus { 7282508ce18SDon Zickus .procname = "softlockup_panic", 7292508ce18SDon Zickus .data = &softlockup_panic, 7302508ce18SDon Zickus .maxlen = sizeof(int), 7312508ce18SDon Zickus .mode = 0644, 7322508ce18SDon Zickus .proc_handler = proc_dointvec_minmax, 7332508ce18SDon Zickus .extra1 = &zero, 7342508ce18SDon Zickus .extra2 = &one, 7352508ce18SDon Zickus }, 736504d7cf1SDon Zickus #endif 73758687acbSDon Zickus #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_LOCKUP_DETECTOR) 7381da177e4SLinus Torvalds { 7391da177e4SLinus Torvalds .procname = "unknown_nmi_panic", 7401da177e4SLinus Torvalds .data = &unknown_nmi_panic, 7411da177e4SLinus Torvalds .maxlen = sizeof (int), 7421da177e4SLinus Torvalds .mode = 0644, 7436d456111SEric W. Biederman .proc_handler = proc_dointvec, 7441da177e4SLinus Torvalds }, 745407984f1SDon Zickus { 746407984f1SDon Zickus .procname = "nmi_watchdog", 747407984f1SDon Zickus .data = &nmi_watchdog_enabled, 748407984f1SDon Zickus .maxlen = sizeof (int), 749407984f1SDon Zickus .mode = 0644, 7506d456111SEric W. Biederman .proc_handler = proc_nmi_enabled, 7511da177e4SLinus Torvalds }, 7521da177e4SLinus Torvalds #endif 7531da177e4SLinus Torvalds #if defined(CONFIG_X86) 7541da177e4SLinus Torvalds { 7558da5addaSDon Zickus .procname = "panic_on_unrecovered_nmi", 7568da5addaSDon Zickus .data = &panic_on_unrecovered_nmi, 7578da5addaSDon Zickus .maxlen = sizeof(int), 7588da5addaSDon Zickus .mode = 0644, 7596d456111SEric W. Biederman .proc_handler = proc_dointvec, 7608da5addaSDon Zickus }, 7618da5addaSDon Zickus { 7625211a242SKurt Garloff .procname = "panic_on_io_nmi", 7635211a242SKurt Garloff .data = &panic_on_io_nmi, 7645211a242SKurt Garloff .maxlen = sizeof(int), 7655211a242SKurt Garloff .mode = 0644, 7666d456111SEric W. Biederman .proc_handler = proc_dointvec, 7675211a242SKurt Garloff }, 7685211a242SKurt Garloff { 7691da177e4SLinus Torvalds .procname = "bootloader_type", 7701da177e4SLinus Torvalds .data = &bootloader_type, 7711da177e4SLinus Torvalds .maxlen = sizeof (int), 7721da177e4SLinus Torvalds .mode = 0444, 7736d456111SEric W. Biederman .proc_handler = proc_dointvec, 7741da177e4SLinus Torvalds }, 7750741f4d2SChuck Ebbert { 7765031296cSH. Peter Anvin .procname = "bootloader_version", 7775031296cSH. Peter Anvin .data = &bootloader_version, 7785031296cSH. Peter Anvin .maxlen = sizeof (int), 7795031296cSH. Peter Anvin .mode = 0444, 7806d456111SEric W. Biederman .proc_handler = proc_dointvec, 7815031296cSH. Peter Anvin }, 7825031296cSH. Peter Anvin { 7830741f4d2SChuck Ebbert .procname = "kstack_depth_to_print", 7840741f4d2SChuck Ebbert .data = &kstack_depth_to_print, 7850741f4d2SChuck Ebbert .maxlen = sizeof(int), 7860741f4d2SChuck Ebbert .mode = 0644, 7876d456111SEric W. Biederman .proc_handler = proc_dointvec, 7880741f4d2SChuck Ebbert }, 7896e7c4025SIngo Molnar { 7906e7c4025SIngo Molnar .procname = "io_delay_type", 7916e7c4025SIngo Molnar .data = &io_delay_type, 7926e7c4025SIngo Molnar .maxlen = sizeof(int), 7936e7c4025SIngo Molnar .mode = 0644, 7946d456111SEric W. Biederman .proc_handler = proc_dointvec, 7956e7c4025SIngo Molnar }, 7961da177e4SLinus Torvalds #endif 7977a9166e3SLuke Yang #if defined(CONFIG_MMU) 7981da177e4SLinus Torvalds { 7991da177e4SLinus Torvalds .procname = "randomize_va_space", 8001da177e4SLinus Torvalds .data = &randomize_va_space, 8011da177e4SLinus Torvalds .maxlen = sizeof(int), 8021da177e4SLinus Torvalds .mode = 0644, 8036d456111SEric W. Biederman .proc_handler = proc_dointvec, 8041da177e4SLinus Torvalds }, 8057a9166e3SLuke Yang #endif 8060152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP) 807951f22d5SMartin Schwidefsky { 808951f22d5SMartin Schwidefsky .procname = "spin_retry", 809951f22d5SMartin Schwidefsky .data = &spin_retry, 810951f22d5SMartin Schwidefsky .maxlen = sizeof (int), 811951f22d5SMartin Schwidefsky .mode = 0644, 8126d456111SEric W. Biederman .proc_handler = proc_dointvec, 813951f22d5SMartin Schwidefsky }, 814951f22d5SMartin Schwidefsky #endif 815673d5b43SLen Brown #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86) 816c255d844SPavel Machek { 817c255d844SPavel Machek .procname = "acpi_video_flags", 81877afcf78SPavel Machek .data = &acpi_realmode_flags, 819c255d844SPavel Machek .maxlen = sizeof (unsigned long), 820c255d844SPavel Machek .mode = 0644, 8216d456111SEric W. Biederman .proc_handler = proc_doulongvec_minmax, 822c255d844SPavel Machek }, 823c255d844SPavel Machek #endif 824d2b176edSJes Sorensen #ifdef CONFIG_IA64 825d2b176edSJes Sorensen { 826d2b176edSJes Sorensen .procname = "ignore-unaligned-usertrap", 827d2b176edSJes Sorensen .data = &no_unaligned_warning, 828d2b176edSJes Sorensen .maxlen = sizeof (int), 829d2b176edSJes Sorensen .mode = 0644, 8306d456111SEric W. Biederman .proc_handler = proc_dointvec, 831d2b176edSJes Sorensen }, 83288fc241fSDoug Chapman { 83388fc241fSDoug Chapman .procname = "unaligned-dump-stack", 83488fc241fSDoug Chapman .data = &unaligned_dump_stack, 83588fc241fSDoug Chapman .maxlen = sizeof (int), 83688fc241fSDoug Chapman .mode = 0644, 8376d456111SEric W. Biederman .proc_handler = proc_dointvec, 83888fc241fSDoug Chapman }, 839d2b176edSJes Sorensen #endif 840e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK 841e162b39aSMandeep Singh Baines { 842e162b39aSMandeep Singh Baines .procname = "hung_task_panic", 843e162b39aSMandeep Singh Baines .data = &sysctl_hung_task_panic, 844e162b39aSMandeep Singh Baines .maxlen = sizeof(int), 845e162b39aSMandeep Singh Baines .mode = 0644, 8466d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 847e162b39aSMandeep Singh Baines .extra1 = &zero, 848e162b39aSMandeep Singh Baines .extra2 = &one, 849e162b39aSMandeep Singh Baines }, 85082a1fcb9SIngo Molnar { 85182a1fcb9SIngo Molnar .procname = "hung_task_check_count", 85282a1fcb9SIngo Molnar .data = &sysctl_hung_task_check_count, 85390739081SIngo Molnar .maxlen = sizeof(unsigned long), 85482a1fcb9SIngo Molnar .mode = 0644, 8556d456111SEric W. Biederman .proc_handler = proc_doulongvec_minmax, 85682a1fcb9SIngo Molnar }, 85782a1fcb9SIngo Molnar { 85882a1fcb9SIngo Molnar .procname = "hung_task_timeout_secs", 85982a1fcb9SIngo Molnar .data = &sysctl_hung_task_timeout_secs, 86090739081SIngo Molnar .maxlen = sizeof(unsigned long), 86182a1fcb9SIngo Molnar .mode = 0644, 8626d456111SEric W. Biederman .proc_handler = proc_dohung_task_timeout_secs, 86382a1fcb9SIngo Molnar }, 86482a1fcb9SIngo Molnar { 86582a1fcb9SIngo Molnar .procname = "hung_task_warnings", 86682a1fcb9SIngo Molnar .data = &sysctl_hung_task_warnings, 86790739081SIngo Molnar .maxlen = sizeof(unsigned long), 86882a1fcb9SIngo Molnar .mode = 0644, 8696d456111SEric W. Biederman .proc_handler = proc_doulongvec_minmax, 87082a1fcb9SIngo Molnar }, 871c4f3b63fSRavikiran G Thirumalai #endif 872bebfa101SAndi Kleen #ifdef CONFIG_COMPAT 873bebfa101SAndi Kleen { 874bebfa101SAndi Kleen .procname = "compat-log", 875bebfa101SAndi Kleen .data = &compat_log, 876bebfa101SAndi Kleen .maxlen = sizeof (int), 877bebfa101SAndi Kleen .mode = 0644, 8786d456111SEric W. Biederman .proc_handler = proc_dointvec, 879bebfa101SAndi Kleen }, 880bebfa101SAndi Kleen #endif 88123f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES 88223f78d4aSIngo Molnar { 88323f78d4aSIngo Molnar .procname = "max_lock_depth", 88423f78d4aSIngo Molnar .data = &max_lock_depth, 88523f78d4aSIngo Molnar .maxlen = sizeof(int), 88623f78d4aSIngo Molnar .mode = 0644, 8876d456111SEric W. Biederman .proc_handler = proc_dointvec, 88823f78d4aSIngo Molnar }, 88923f78d4aSIngo Molnar #endif 89010a0a8d4SJeremy Fitzhardinge { 89110a0a8d4SJeremy Fitzhardinge .procname = "poweroff_cmd", 89210a0a8d4SJeremy Fitzhardinge .data = &poweroff_cmd, 89310a0a8d4SJeremy Fitzhardinge .maxlen = POWEROFF_CMD_PATH_LEN, 89410a0a8d4SJeremy Fitzhardinge .mode = 0644, 8956d456111SEric W. Biederman .proc_handler = proc_dostring, 89610a0a8d4SJeremy Fitzhardinge }, 8970b77f5bfSDavid Howells #ifdef CONFIG_KEYS 8980b77f5bfSDavid Howells { 8990b77f5bfSDavid Howells .procname = "keys", 9000b77f5bfSDavid Howells .mode = 0555, 9010b77f5bfSDavid Howells .child = key_sysctls, 9020b77f5bfSDavid Howells }, 9030b77f5bfSDavid Howells #endif 90431a72bceSPaul E. McKenney #ifdef CONFIG_RCU_TORTURE_TEST 90531a72bceSPaul E. McKenney { 90631a72bceSPaul E. McKenney .procname = "rcutorture_runnable", 90731a72bceSPaul E. McKenney .data = &rcutorture_runnable, 90831a72bceSPaul E. McKenney .maxlen = sizeof(int), 90931a72bceSPaul E. McKenney .mode = 0644, 9106d456111SEric W. Biederman .proc_handler = proc_dointvec, 91131a72bceSPaul E. McKenney }, 91231a72bceSPaul E. McKenney #endif 913cdd6c482SIngo Molnar #ifdef CONFIG_PERF_EVENTS 9141ccd1549SPeter Zijlstra { 915cdd6c482SIngo Molnar .procname = "perf_event_paranoid", 916cdd6c482SIngo Molnar .data = &sysctl_perf_event_paranoid, 917cdd6c482SIngo Molnar .maxlen = sizeof(sysctl_perf_event_paranoid), 9181ccd1549SPeter Zijlstra .mode = 0644, 9196d456111SEric W. Biederman .proc_handler = proc_dointvec, 9201ccd1549SPeter Zijlstra }, 921c5078f78SPeter Zijlstra { 922cdd6c482SIngo Molnar .procname = "perf_event_mlock_kb", 923cdd6c482SIngo Molnar .data = &sysctl_perf_event_mlock, 924cdd6c482SIngo Molnar .maxlen = sizeof(sysctl_perf_event_mlock), 925c5078f78SPeter Zijlstra .mode = 0644, 9266d456111SEric W. Biederman .proc_handler = proc_dointvec, 927c5078f78SPeter Zijlstra }, 928a78ac325SPeter Zijlstra { 929cdd6c482SIngo Molnar .procname = "perf_event_max_sample_rate", 930cdd6c482SIngo Molnar .data = &sysctl_perf_event_sample_rate, 931cdd6c482SIngo Molnar .maxlen = sizeof(sysctl_perf_event_sample_rate), 932a78ac325SPeter Zijlstra .mode = 0644, 9336d456111SEric W. Biederman .proc_handler = proc_dointvec, 934a78ac325SPeter Zijlstra }, 9351ccd1549SPeter Zijlstra #endif 936dfec072eSVegard Nossum #ifdef CONFIG_KMEMCHECK 937dfec072eSVegard Nossum { 938dfec072eSVegard Nossum .procname = "kmemcheck", 939dfec072eSVegard Nossum .data = &kmemcheck_enabled, 940dfec072eSVegard Nossum .maxlen = sizeof(int), 941dfec072eSVegard Nossum .mode = 0644, 9426d456111SEric W. Biederman .proc_handler = proc_dointvec, 943dfec072eSVegard Nossum }, 944dfec072eSVegard Nossum #endif 945cb684b5bSJens Axboe #ifdef CONFIG_BLOCK 9465e605b64SJens Axboe { 9475e605b64SJens Axboe .procname = "blk_iopoll", 9485e605b64SJens Axboe .data = &blk_iopoll_enabled, 9495e605b64SJens Axboe .maxlen = sizeof(int), 9505e605b64SJens Axboe .mode = 0644, 9516d456111SEric W. Biederman .proc_handler = proc_dointvec, 9525e605b64SJens Axboe }, 953cb684b5bSJens Axboe #endif 954ed2c12f3SAndrew Morton /* 955ed2c12f3SAndrew Morton * NOTE: do not add new entries to this table unless you have read 956ed2c12f3SAndrew Morton * Documentation/sysctl/ctl_unnumbered.txt 957ed2c12f3SAndrew Morton */ 9586fce56ecSEric W. Biederman { } 9591da177e4SLinus Torvalds }; 9601da177e4SLinus Torvalds 961d8217f07SEric W. Biederman static struct ctl_table vm_table[] = { 9621da177e4SLinus Torvalds { 9631da177e4SLinus Torvalds .procname = "overcommit_memory", 9641da177e4SLinus Torvalds .data = &sysctl_overcommit_memory, 9651da177e4SLinus Torvalds .maxlen = sizeof(sysctl_overcommit_memory), 9661da177e4SLinus Torvalds .mode = 0644, 9676d456111SEric W. Biederman .proc_handler = proc_dointvec, 9681da177e4SLinus Torvalds }, 9691da177e4SLinus Torvalds { 970fadd8fbdSKAMEZAWA Hiroyuki .procname = "panic_on_oom", 971fadd8fbdSKAMEZAWA Hiroyuki .data = &sysctl_panic_on_oom, 972fadd8fbdSKAMEZAWA Hiroyuki .maxlen = sizeof(sysctl_panic_on_oom), 973fadd8fbdSKAMEZAWA Hiroyuki .mode = 0644, 9746d456111SEric W. Biederman .proc_handler = proc_dointvec, 975fadd8fbdSKAMEZAWA Hiroyuki }, 976fadd8fbdSKAMEZAWA Hiroyuki { 977fe071d7eSDavid Rientjes .procname = "oom_kill_allocating_task", 978fe071d7eSDavid Rientjes .data = &sysctl_oom_kill_allocating_task, 979fe071d7eSDavid Rientjes .maxlen = sizeof(sysctl_oom_kill_allocating_task), 980fe071d7eSDavid Rientjes .mode = 0644, 9816d456111SEric W. Biederman .proc_handler = proc_dointvec, 982fe071d7eSDavid Rientjes }, 983fe071d7eSDavid Rientjes { 984fef1bdd6SDavid Rientjes .procname = "oom_dump_tasks", 985fef1bdd6SDavid Rientjes .data = &sysctl_oom_dump_tasks, 986fef1bdd6SDavid Rientjes .maxlen = sizeof(sysctl_oom_dump_tasks), 987fef1bdd6SDavid Rientjes .mode = 0644, 9886d456111SEric W. Biederman .proc_handler = proc_dointvec, 989fef1bdd6SDavid Rientjes }, 990fef1bdd6SDavid Rientjes { 9911da177e4SLinus Torvalds .procname = "overcommit_ratio", 9921da177e4SLinus Torvalds .data = &sysctl_overcommit_ratio, 9931da177e4SLinus Torvalds .maxlen = sizeof(sysctl_overcommit_ratio), 9941da177e4SLinus Torvalds .mode = 0644, 9956d456111SEric W. Biederman .proc_handler = proc_dointvec, 9961da177e4SLinus Torvalds }, 9971da177e4SLinus Torvalds { 9981da177e4SLinus Torvalds .procname = "page-cluster", 9991da177e4SLinus Torvalds .data = &page_cluster, 10001da177e4SLinus Torvalds .maxlen = sizeof(int), 10011da177e4SLinus Torvalds .mode = 0644, 10026d456111SEric W. Biederman .proc_handler = proc_dointvec, 10031da177e4SLinus Torvalds }, 10041da177e4SLinus Torvalds { 10051da177e4SLinus Torvalds .procname = "dirty_background_ratio", 10061da177e4SLinus Torvalds .data = &dirty_background_ratio, 10071da177e4SLinus Torvalds .maxlen = sizeof(dirty_background_ratio), 10081da177e4SLinus Torvalds .mode = 0644, 10096d456111SEric W. Biederman .proc_handler = dirty_background_ratio_handler, 10101da177e4SLinus Torvalds .extra1 = &zero, 10111da177e4SLinus Torvalds .extra2 = &one_hundred, 10121da177e4SLinus Torvalds }, 10131da177e4SLinus Torvalds { 10142da02997SDavid Rientjes .procname = "dirty_background_bytes", 10152da02997SDavid Rientjes .data = &dirty_background_bytes, 10162da02997SDavid Rientjes .maxlen = sizeof(dirty_background_bytes), 10172da02997SDavid Rientjes .mode = 0644, 10186d456111SEric W. Biederman .proc_handler = dirty_background_bytes_handler, 1019fc3501d4SSven Wegener .extra1 = &one_ul, 10202da02997SDavid Rientjes }, 10212da02997SDavid Rientjes { 10221da177e4SLinus Torvalds .procname = "dirty_ratio", 10231da177e4SLinus Torvalds .data = &vm_dirty_ratio, 10241da177e4SLinus Torvalds .maxlen = sizeof(vm_dirty_ratio), 10251da177e4SLinus Torvalds .mode = 0644, 10266d456111SEric W. Biederman .proc_handler = dirty_ratio_handler, 10271da177e4SLinus Torvalds .extra1 = &zero, 10281da177e4SLinus Torvalds .extra2 = &one_hundred, 10291da177e4SLinus Torvalds }, 10301da177e4SLinus Torvalds { 10312da02997SDavid Rientjes .procname = "dirty_bytes", 10322da02997SDavid Rientjes .data = &vm_dirty_bytes, 10332da02997SDavid Rientjes .maxlen = sizeof(vm_dirty_bytes), 10342da02997SDavid Rientjes .mode = 0644, 10356d456111SEric W. Biederman .proc_handler = dirty_bytes_handler, 10369e4a5bdaSAndrea Righi .extra1 = &dirty_bytes_min, 10372da02997SDavid Rientjes }, 10382da02997SDavid Rientjes { 10391da177e4SLinus Torvalds .procname = "dirty_writeback_centisecs", 1040f6ef9438SBart Samwel .data = &dirty_writeback_interval, 1041f6ef9438SBart Samwel .maxlen = sizeof(dirty_writeback_interval), 10421da177e4SLinus Torvalds .mode = 0644, 10436d456111SEric W. Biederman .proc_handler = dirty_writeback_centisecs_handler, 10441da177e4SLinus Torvalds }, 10451da177e4SLinus Torvalds { 10461da177e4SLinus Torvalds .procname = "dirty_expire_centisecs", 1047f6ef9438SBart Samwel .data = &dirty_expire_interval, 1048f6ef9438SBart Samwel .maxlen = sizeof(dirty_expire_interval), 10491da177e4SLinus Torvalds .mode = 0644, 10506d456111SEric W. Biederman .proc_handler = proc_dointvec, 10511da177e4SLinus Torvalds }, 10521da177e4SLinus Torvalds { 10531da177e4SLinus Torvalds .procname = "nr_pdflush_threads", 10541da177e4SLinus Torvalds .data = &nr_pdflush_threads, 10551da177e4SLinus Torvalds .maxlen = sizeof nr_pdflush_threads, 10561da177e4SLinus Torvalds .mode = 0444 /* read-only*/, 10576d456111SEric W. Biederman .proc_handler = proc_dointvec, 10581da177e4SLinus Torvalds }, 10591da177e4SLinus Torvalds { 10601da177e4SLinus Torvalds .procname = "swappiness", 10611da177e4SLinus Torvalds .data = &vm_swappiness, 10621da177e4SLinus Torvalds .maxlen = sizeof(vm_swappiness), 10631da177e4SLinus Torvalds .mode = 0644, 10646d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 10651da177e4SLinus Torvalds .extra1 = &zero, 10661da177e4SLinus Torvalds .extra2 = &one_hundred, 10671da177e4SLinus Torvalds }, 10681da177e4SLinus Torvalds #ifdef CONFIG_HUGETLB_PAGE 10691da177e4SLinus Torvalds { 10701da177e4SLinus Torvalds .procname = "nr_hugepages", 1071e5ff2159SAndi Kleen .data = NULL, 10721da177e4SLinus Torvalds .maxlen = sizeof(unsigned long), 10731da177e4SLinus Torvalds .mode = 0644, 10746d456111SEric W. Biederman .proc_handler = hugetlb_sysctl_handler, 10751da177e4SLinus Torvalds .extra1 = (void *)&hugetlb_zero, 10761da177e4SLinus Torvalds .extra2 = (void *)&hugetlb_infinity, 10771da177e4SLinus Torvalds }, 107806808b08SLee Schermerhorn #ifdef CONFIG_NUMA 107906808b08SLee Schermerhorn { 108006808b08SLee Schermerhorn .procname = "nr_hugepages_mempolicy", 108106808b08SLee Schermerhorn .data = NULL, 108206808b08SLee Schermerhorn .maxlen = sizeof(unsigned long), 108306808b08SLee Schermerhorn .mode = 0644, 108406808b08SLee Schermerhorn .proc_handler = &hugetlb_mempolicy_sysctl_handler, 108506808b08SLee Schermerhorn .extra1 = (void *)&hugetlb_zero, 108606808b08SLee Schermerhorn .extra2 = (void *)&hugetlb_infinity, 108706808b08SLee Schermerhorn }, 108806808b08SLee Schermerhorn #endif 10891da177e4SLinus Torvalds { 10901da177e4SLinus Torvalds .procname = "hugetlb_shm_group", 10911da177e4SLinus Torvalds .data = &sysctl_hugetlb_shm_group, 10921da177e4SLinus Torvalds .maxlen = sizeof(gid_t), 10931da177e4SLinus Torvalds .mode = 0644, 10946d456111SEric W. Biederman .proc_handler = proc_dointvec, 10951da177e4SLinus Torvalds }, 1096396faf03SMel Gorman { 1097396faf03SMel Gorman .procname = "hugepages_treat_as_movable", 1098396faf03SMel Gorman .data = &hugepages_treat_as_movable, 1099396faf03SMel Gorman .maxlen = sizeof(int), 1100396faf03SMel Gorman .mode = 0644, 11016d456111SEric W. Biederman .proc_handler = hugetlb_treat_movable_handler, 1102396faf03SMel Gorman }, 110354f9f80dSAdam Litke { 1104d1c3fb1fSNishanth Aravamudan .procname = "nr_overcommit_hugepages", 1105e5ff2159SAndi Kleen .data = NULL, 1106e5ff2159SAndi Kleen .maxlen = sizeof(unsigned long), 1107d1c3fb1fSNishanth Aravamudan .mode = 0644, 11086d456111SEric W. Biederman .proc_handler = hugetlb_overcommit_handler, 1109e5ff2159SAndi Kleen .extra1 = (void *)&hugetlb_zero, 1110e5ff2159SAndi Kleen .extra2 = (void *)&hugetlb_infinity, 1111d1c3fb1fSNishanth Aravamudan }, 11121da177e4SLinus Torvalds #endif 11131da177e4SLinus Torvalds { 11141da177e4SLinus Torvalds .procname = "lowmem_reserve_ratio", 11151da177e4SLinus Torvalds .data = &sysctl_lowmem_reserve_ratio, 11161da177e4SLinus Torvalds .maxlen = sizeof(sysctl_lowmem_reserve_ratio), 11171da177e4SLinus Torvalds .mode = 0644, 11186d456111SEric W. Biederman .proc_handler = lowmem_reserve_ratio_sysctl_handler, 11191da177e4SLinus Torvalds }, 11201da177e4SLinus Torvalds { 11219d0243bcSAndrew Morton .procname = "drop_caches", 11229d0243bcSAndrew Morton .data = &sysctl_drop_caches, 11239d0243bcSAndrew Morton .maxlen = sizeof(int), 11249d0243bcSAndrew Morton .mode = 0644, 11259d0243bcSAndrew Morton .proc_handler = drop_caches_sysctl_handler, 11269d0243bcSAndrew Morton }, 112776ab0f53SMel Gorman #ifdef CONFIG_COMPACTION 112876ab0f53SMel Gorman { 112976ab0f53SMel Gorman .procname = "compact_memory", 113076ab0f53SMel Gorman .data = &sysctl_compact_memory, 113176ab0f53SMel Gorman .maxlen = sizeof(int), 113276ab0f53SMel Gorman .mode = 0200, 113376ab0f53SMel Gorman .proc_handler = sysctl_compaction_handler, 113476ab0f53SMel Gorman }, 11355e771905SMel Gorman { 11365e771905SMel Gorman .procname = "extfrag_threshold", 11375e771905SMel Gorman .data = &sysctl_extfrag_threshold, 11385e771905SMel Gorman .maxlen = sizeof(int), 11395e771905SMel Gorman .mode = 0644, 11405e771905SMel Gorman .proc_handler = sysctl_extfrag_handler, 11415e771905SMel Gorman .extra1 = &min_extfrag_threshold, 11425e771905SMel Gorman .extra2 = &max_extfrag_threshold, 11435e771905SMel Gorman }, 11445e771905SMel Gorman 114576ab0f53SMel Gorman #endif /* CONFIG_COMPACTION */ 11469d0243bcSAndrew Morton { 11471da177e4SLinus Torvalds .procname = "min_free_kbytes", 11481da177e4SLinus Torvalds .data = &min_free_kbytes, 11491da177e4SLinus Torvalds .maxlen = sizeof(min_free_kbytes), 11501da177e4SLinus Torvalds .mode = 0644, 11516d456111SEric W. Biederman .proc_handler = min_free_kbytes_sysctl_handler, 11521da177e4SLinus Torvalds .extra1 = &zero, 11531da177e4SLinus Torvalds }, 11548ad4b1fbSRohit Seth { 11558ad4b1fbSRohit Seth .procname = "percpu_pagelist_fraction", 11568ad4b1fbSRohit Seth .data = &percpu_pagelist_fraction, 11578ad4b1fbSRohit Seth .maxlen = sizeof(percpu_pagelist_fraction), 11588ad4b1fbSRohit Seth .mode = 0644, 11596d456111SEric W. Biederman .proc_handler = percpu_pagelist_fraction_sysctl_handler, 11608ad4b1fbSRohit Seth .extra1 = &min_percpu_pagelist_fract, 11618ad4b1fbSRohit Seth }, 11621da177e4SLinus Torvalds #ifdef CONFIG_MMU 11631da177e4SLinus Torvalds { 11641da177e4SLinus Torvalds .procname = "max_map_count", 11651da177e4SLinus Torvalds .data = &sysctl_max_map_count, 11661da177e4SLinus Torvalds .maxlen = sizeof(sysctl_max_map_count), 11671da177e4SLinus Torvalds .mode = 0644, 11683e26120cSWANG Cong .proc_handler = proc_dointvec_minmax, 116970da2340SAmerigo Wang .extra1 = &zero, 11701da177e4SLinus Torvalds }, 1171dd8632a1SPaul Mundt #else 1172dd8632a1SPaul Mundt { 1173dd8632a1SPaul Mundt .procname = "nr_trim_pages", 1174dd8632a1SPaul Mundt .data = &sysctl_nr_trim_pages, 1175dd8632a1SPaul Mundt .maxlen = sizeof(sysctl_nr_trim_pages), 1176dd8632a1SPaul Mundt .mode = 0644, 11776d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 1178dd8632a1SPaul Mundt .extra1 = &zero, 1179dd8632a1SPaul Mundt }, 11801da177e4SLinus Torvalds #endif 11811da177e4SLinus Torvalds { 11821da177e4SLinus Torvalds .procname = "laptop_mode", 11831da177e4SLinus Torvalds .data = &laptop_mode, 11841da177e4SLinus Torvalds .maxlen = sizeof(laptop_mode), 11851da177e4SLinus Torvalds .mode = 0644, 11866d456111SEric W. Biederman .proc_handler = proc_dointvec_jiffies, 11871da177e4SLinus Torvalds }, 11881da177e4SLinus Torvalds { 11891da177e4SLinus Torvalds .procname = "block_dump", 11901da177e4SLinus Torvalds .data = &block_dump, 11911da177e4SLinus Torvalds .maxlen = sizeof(block_dump), 11921da177e4SLinus Torvalds .mode = 0644, 11936d456111SEric W. Biederman .proc_handler = proc_dointvec, 11941da177e4SLinus Torvalds .extra1 = &zero, 11951da177e4SLinus Torvalds }, 11961da177e4SLinus Torvalds { 11971da177e4SLinus Torvalds .procname = "vfs_cache_pressure", 11981da177e4SLinus Torvalds .data = &sysctl_vfs_cache_pressure, 11991da177e4SLinus Torvalds .maxlen = sizeof(sysctl_vfs_cache_pressure), 12001da177e4SLinus Torvalds .mode = 0644, 12016d456111SEric W. Biederman .proc_handler = proc_dointvec, 12021da177e4SLinus Torvalds .extra1 = &zero, 12031da177e4SLinus Torvalds }, 12041da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT 12051da177e4SLinus Torvalds { 12061da177e4SLinus Torvalds .procname = "legacy_va_layout", 12071da177e4SLinus Torvalds .data = &sysctl_legacy_va_layout, 12081da177e4SLinus Torvalds .maxlen = sizeof(sysctl_legacy_va_layout), 12091da177e4SLinus Torvalds .mode = 0644, 12106d456111SEric W. Biederman .proc_handler = proc_dointvec, 12111da177e4SLinus Torvalds .extra1 = &zero, 12121da177e4SLinus Torvalds }, 12131da177e4SLinus Torvalds #endif 12141743660bSChristoph Lameter #ifdef CONFIG_NUMA 12151743660bSChristoph Lameter { 12161743660bSChristoph Lameter .procname = "zone_reclaim_mode", 12171743660bSChristoph Lameter .data = &zone_reclaim_mode, 12181743660bSChristoph Lameter .maxlen = sizeof(zone_reclaim_mode), 12191743660bSChristoph Lameter .mode = 0644, 12206d456111SEric W. Biederman .proc_handler = proc_dointvec, 1221c84db23cSChristoph Lameter .extra1 = &zero, 12221743660bSChristoph Lameter }, 12239614634fSChristoph Lameter { 12249614634fSChristoph Lameter .procname = "min_unmapped_ratio", 12259614634fSChristoph Lameter .data = &sysctl_min_unmapped_ratio, 12269614634fSChristoph Lameter .maxlen = sizeof(sysctl_min_unmapped_ratio), 12279614634fSChristoph Lameter .mode = 0644, 12286d456111SEric W. Biederman .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler, 12299614634fSChristoph Lameter .extra1 = &zero, 12309614634fSChristoph Lameter .extra2 = &one_hundred, 12319614634fSChristoph Lameter }, 12320ff38490SChristoph Lameter { 12330ff38490SChristoph Lameter .procname = "min_slab_ratio", 12340ff38490SChristoph Lameter .data = &sysctl_min_slab_ratio, 12350ff38490SChristoph Lameter .maxlen = sizeof(sysctl_min_slab_ratio), 12360ff38490SChristoph Lameter .mode = 0644, 12376d456111SEric W. Biederman .proc_handler = sysctl_min_slab_ratio_sysctl_handler, 12380ff38490SChristoph Lameter .extra1 = &zero, 12390ff38490SChristoph Lameter .extra2 = &one_hundred, 12400ff38490SChristoph Lameter }, 12411743660bSChristoph Lameter #endif 124277461ab3SChristoph Lameter #ifdef CONFIG_SMP 124377461ab3SChristoph Lameter { 124477461ab3SChristoph Lameter .procname = "stat_interval", 124577461ab3SChristoph Lameter .data = &sysctl_stat_interval, 124677461ab3SChristoph Lameter .maxlen = sizeof(sysctl_stat_interval), 124777461ab3SChristoph Lameter .mode = 0644, 12486d456111SEric W. Biederman .proc_handler = proc_dointvec_jiffies, 124977461ab3SChristoph Lameter }, 125077461ab3SChristoph Lameter #endif 12516e141546SDavid Howells #ifdef CONFIG_MMU 1252ed032189SEric Paris { 1253ed032189SEric Paris .procname = "mmap_min_addr", 1254788084abSEric Paris .data = &dac_mmap_min_addr, 1255ed032189SEric Paris .maxlen = sizeof(unsigned long), 1256ed032189SEric Paris .mode = 0644, 12576d456111SEric W. Biederman .proc_handler = mmap_min_addr_handler, 1258ed032189SEric Paris }, 12596e141546SDavid Howells #endif 1260f0c0b2b8SKAMEZAWA Hiroyuki #ifdef CONFIG_NUMA 1261f0c0b2b8SKAMEZAWA Hiroyuki { 1262f0c0b2b8SKAMEZAWA Hiroyuki .procname = "numa_zonelist_order", 1263f0c0b2b8SKAMEZAWA Hiroyuki .data = &numa_zonelist_order, 1264f0c0b2b8SKAMEZAWA Hiroyuki .maxlen = NUMA_ZONELIST_ORDER_LEN, 1265f0c0b2b8SKAMEZAWA Hiroyuki .mode = 0644, 12666d456111SEric W. Biederman .proc_handler = numa_zonelist_order_handler, 1267f0c0b2b8SKAMEZAWA Hiroyuki }, 1268f0c0b2b8SKAMEZAWA Hiroyuki #endif 12692b8232ceSAl Viro #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \ 12705c36e657SPaul Mundt (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)) 1271e6e5494cSIngo Molnar { 1272e6e5494cSIngo Molnar .procname = "vdso_enabled", 1273e6e5494cSIngo Molnar .data = &vdso_enabled, 1274e6e5494cSIngo Molnar .maxlen = sizeof(vdso_enabled), 1275e6e5494cSIngo Molnar .mode = 0644, 12766d456111SEric W. Biederman .proc_handler = proc_dointvec, 1277e6e5494cSIngo Molnar .extra1 = &zero, 1278e6e5494cSIngo Molnar }, 1279e6e5494cSIngo Molnar #endif 1280195cf453SBron Gondwana #ifdef CONFIG_HIGHMEM 1281195cf453SBron Gondwana { 1282195cf453SBron Gondwana .procname = "highmem_is_dirtyable", 1283195cf453SBron Gondwana .data = &vm_highmem_is_dirtyable, 1284195cf453SBron Gondwana .maxlen = sizeof(vm_highmem_is_dirtyable), 1285195cf453SBron Gondwana .mode = 0644, 12866d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 1287195cf453SBron Gondwana .extra1 = &zero, 1288195cf453SBron Gondwana .extra2 = &one, 1289195cf453SBron Gondwana }, 1290195cf453SBron Gondwana #endif 12914be6f6bbSPeter Zijlstra { 12924be6f6bbSPeter Zijlstra .procname = "scan_unevictable_pages", 12934be6f6bbSPeter Zijlstra .data = &scan_unevictable_pages, 12944be6f6bbSPeter Zijlstra .maxlen = sizeof(scan_unevictable_pages), 12954be6f6bbSPeter Zijlstra .mode = 0644, 12966d456111SEric W. Biederman .proc_handler = scan_unevictable_handler, 12974be6f6bbSPeter Zijlstra }, 12986a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE 12996a46079cSAndi Kleen { 13006a46079cSAndi Kleen .procname = "memory_failure_early_kill", 13016a46079cSAndi Kleen .data = &sysctl_memory_failure_early_kill, 13026a46079cSAndi Kleen .maxlen = sizeof(sysctl_memory_failure_early_kill), 13036a46079cSAndi Kleen .mode = 0644, 13046d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 13056a46079cSAndi Kleen .extra1 = &zero, 13066a46079cSAndi Kleen .extra2 = &one, 13076a46079cSAndi Kleen }, 13086a46079cSAndi Kleen { 13096a46079cSAndi Kleen .procname = "memory_failure_recovery", 13106a46079cSAndi Kleen .data = &sysctl_memory_failure_recovery, 13116a46079cSAndi Kleen .maxlen = sizeof(sysctl_memory_failure_recovery), 13126a46079cSAndi Kleen .mode = 0644, 13136d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 13146a46079cSAndi Kleen .extra1 = &zero, 13156a46079cSAndi Kleen .extra2 = &one, 13166a46079cSAndi Kleen }, 13176a46079cSAndi Kleen #endif 13186a46079cSAndi Kleen 13192be7fe07SAndrew Morton /* 13202be7fe07SAndrew Morton * NOTE: do not add new entries to this table unless you have read 13212be7fe07SAndrew Morton * Documentation/sysctl/ctl_unnumbered.txt 13222be7fe07SAndrew Morton */ 13236fce56ecSEric W. Biederman { } 13241da177e4SLinus Torvalds }; 13251da177e4SLinus Torvalds 13262abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) 1327d8217f07SEric W. Biederman static struct ctl_table binfmt_misc_table[] = { 13286fce56ecSEric W. Biederman { } 13292abc26fcSEric W. Biederman }; 13302abc26fcSEric W. Biederman #endif 13312abc26fcSEric W. Biederman 1332d8217f07SEric W. Biederman static struct ctl_table fs_table[] = { 13331da177e4SLinus Torvalds { 13341da177e4SLinus Torvalds .procname = "inode-nr", 13351da177e4SLinus Torvalds .data = &inodes_stat, 13361da177e4SLinus Torvalds .maxlen = 2*sizeof(int), 13371da177e4SLinus Torvalds .mode = 0444, 1338cffbc8aaSDave Chinner .proc_handler = proc_nr_inodes, 13391da177e4SLinus Torvalds }, 13401da177e4SLinus Torvalds { 13411da177e4SLinus Torvalds .procname = "inode-state", 13421da177e4SLinus Torvalds .data = &inodes_stat, 13431da177e4SLinus Torvalds .maxlen = 7*sizeof(int), 13441da177e4SLinus Torvalds .mode = 0444, 1345cffbc8aaSDave Chinner .proc_handler = proc_nr_inodes, 13461da177e4SLinus Torvalds }, 13471da177e4SLinus Torvalds { 13481da177e4SLinus Torvalds .procname = "file-nr", 13491da177e4SLinus Torvalds .data = &files_stat, 1350518de9b3SEric Dumazet .maxlen = sizeof(files_stat), 13511da177e4SLinus Torvalds .mode = 0444, 13526d456111SEric W. Biederman .proc_handler = proc_nr_files, 13531da177e4SLinus Torvalds }, 13541da177e4SLinus Torvalds { 13551da177e4SLinus Torvalds .procname = "file-max", 13561da177e4SLinus Torvalds .data = &files_stat.max_files, 1357518de9b3SEric Dumazet .maxlen = sizeof(files_stat.max_files), 13581da177e4SLinus Torvalds .mode = 0644, 1359518de9b3SEric Dumazet .proc_handler = proc_doulongvec_minmax, 13601da177e4SLinus Torvalds }, 13611da177e4SLinus Torvalds { 13629cfe015aSEric Dumazet .procname = "nr_open", 13639cfe015aSEric Dumazet .data = &sysctl_nr_open, 13649cfe015aSEric Dumazet .maxlen = sizeof(int), 13659cfe015aSEric Dumazet .mode = 0644, 13666d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 1367eceea0b3SAl Viro .extra1 = &sysctl_nr_open_min, 1368eceea0b3SAl Viro .extra2 = &sysctl_nr_open_max, 13699cfe015aSEric Dumazet }, 13709cfe015aSEric Dumazet { 13711da177e4SLinus Torvalds .procname = "dentry-state", 13721da177e4SLinus Torvalds .data = &dentry_stat, 13731da177e4SLinus Torvalds .maxlen = 6*sizeof(int), 13741da177e4SLinus Torvalds .mode = 0444, 1375312d3ca8SChristoph Hellwig .proc_handler = proc_nr_dentry, 13761da177e4SLinus Torvalds }, 13771da177e4SLinus Torvalds { 13781da177e4SLinus Torvalds .procname = "overflowuid", 13791da177e4SLinus Torvalds .data = &fs_overflowuid, 13801da177e4SLinus Torvalds .maxlen = sizeof(int), 13811da177e4SLinus Torvalds .mode = 0644, 13826d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 13831da177e4SLinus Torvalds .extra1 = &minolduid, 13841da177e4SLinus Torvalds .extra2 = &maxolduid, 13851da177e4SLinus Torvalds }, 13861da177e4SLinus Torvalds { 13871da177e4SLinus Torvalds .procname = "overflowgid", 13881da177e4SLinus Torvalds .data = &fs_overflowgid, 13891da177e4SLinus Torvalds .maxlen = sizeof(int), 13901da177e4SLinus Torvalds .mode = 0644, 13916d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 13921da177e4SLinus Torvalds .extra1 = &minolduid, 13931da177e4SLinus Torvalds .extra2 = &maxolduid, 13941da177e4SLinus Torvalds }, 1395bfcd17a6SThomas Petazzoni #ifdef CONFIG_FILE_LOCKING 13961da177e4SLinus Torvalds { 13971da177e4SLinus Torvalds .procname = "leases-enable", 13981da177e4SLinus Torvalds .data = &leases_enable, 13991da177e4SLinus Torvalds .maxlen = sizeof(int), 14001da177e4SLinus Torvalds .mode = 0644, 14016d456111SEric W. Biederman .proc_handler = proc_dointvec, 14021da177e4SLinus Torvalds }, 1403bfcd17a6SThomas Petazzoni #endif 14041da177e4SLinus Torvalds #ifdef CONFIG_DNOTIFY 14051da177e4SLinus Torvalds { 14061da177e4SLinus Torvalds .procname = "dir-notify-enable", 14071da177e4SLinus Torvalds .data = &dir_notify_enable, 14081da177e4SLinus Torvalds .maxlen = sizeof(int), 14091da177e4SLinus Torvalds .mode = 0644, 14106d456111SEric W. Biederman .proc_handler = proc_dointvec, 14111da177e4SLinus Torvalds }, 14121da177e4SLinus Torvalds #endif 14131da177e4SLinus Torvalds #ifdef CONFIG_MMU 1414bfcd17a6SThomas Petazzoni #ifdef CONFIG_FILE_LOCKING 14151da177e4SLinus Torvalds { 14161da177e4SLinus Torvalds .procname = "lease-break-time", 14171da177e4SLinus Torvalds .data = &lease_break_time, 14181da177e4SLinus Torvalds .maxlen = sizeof(int), 14191da177e4SLinus Torvalds .mode = 0644, 14206d456111SEric W. Biederman .proc_handler = proc_dointvec, 14211da177e4SLinus Torvalds }, 1422bfcd17a6SThomas Petazzoni #endif 1423ebf3f09cSThomas Petazzoni #ifdef CONFIG_AIO 14241da177e4SLinus Torvalds { 14251da177e4SLinus Torvalds .procname = "aio-nr", 14261da177e4SLinus Torvalds .data = &aio_nr, 14271da177e4SLinus Torvalds .maxlen = sizeof(aio_nr), 14281da177e4SLinus Torvalds .mode = 0444, 14296d456111SEric W. Biederman .proc_handler = proc_doulongvec_minmax, 14301da177e4SLinus Torvalds }, 14311da177e4SLinus Torvalds { 14321da177e4SLinus Torvalds .procname = "aio-max-nr", 14331da177e4SLinus Torvalds .data = &aio_max_nr, 14341da177e4SLinus Torvalds .maxlen = sizeof(aio_max_nr), 14351da177e4SLinus Torvalds .mode = 0644, 14366d456111SEric W. Biederman .proc_handler = proc_doulongvec_minmax, 14371da177e4SLinus Torvalds }, 1438ebf3f09cSThomas Petazzoni #endif /* CONFIG_AIO */ 14392d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER 14400399cb08SRobert Love { 14410399cb08SRobert Love .procname = "inotify", 14420399cb08SRobert Love .mode = 0555, 14430399cb08SRobert Love .child = inotify_table, 14440399cb08SRobert Love }, 14450399cb08SRobert Love #endif 14467ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL 14477ef9964eSDavide Libenzi { 14487ef9964eSDavide Libenzi .procname = "epoll", 14497ef9964eSDavide Libenzi .mode = 0555, 14507ef9964eSDavide Libenzi .child = epoll_table, 14517ef9964eSDavide Libenzi }, 14527ef9964eSDavide Libenzi #endif 14531da177e4SLinus Torvalds #endif 1454d6e71144SAlan Cox { 1455d6e71144SAlan Cox .procname = "suid_dumpable", 1456d6e71144SAlan Cox .data = &suid_dumpable, 1457d6e71144SAlan Cox .maxlen = sizeof(int), 1458d6e71144SAlan Cox .mode = 0644, 14596d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 14608e654fbaSMatthew Wilcox .extra1 = &zero, 14618e654fbaSMatthew Wilcox .extra2 = &two, 1462d6e71144SAlan Cox }, 14632abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) 14642abc26fcSEric W. Biederman { 14652abc26fcSEric W. Biederman .procname = "binfmt_misc", 14662abc26fcSEric W. Biederman .mode = 0555, 14672abc26fcSEric W. Biederman .child = binfmt_misc_table, 14682abc26fcSEric W. Biederman }, 14692abc26fcSEric W. Biederman #endif 1470b492e95bSJens Axboe { 1471ff9da691SJens Axboe .procname = "pipe-max-size", 1472ff9da691SJens Axboe .data = &pipe_max_size, 1473b492e95bSJens Axboe .maxlen = sizeof(int), 1474b492e95bSJens Axboe .mode = 0644, 1475ff9da691SJens Axboe .proc_handler = &pipe_proc_fn, 1476ff9da691SJens Axboe .extra1 = &pipe_min_size, 1477b492e95bSJens Axboe }, 14782be7fe07SAndrew Morton /* 14792be7fe07SAndrew Morton * NOTE: do not add new entries to this table unless you have read 14802be7fe07SAndrew Morton * Documentation/sysctl/ctl_unnumbered.txt 14812be7fe07SAndrew Morton */ 14826fce56ecSEric W. Biederman { } 14831da177e4SLinus Torvalds }; 14841da177e4SLinus Torvalds 1485d8217f07SEric W. Biederman static struct ctl_table debug_table[] = { 1486ab3c68eeSHeiko Carstens #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \ 1487ab3c68eeSHeiko Carstens defined(CONFIG_S390) 1488abd4f750SMasoud Asgharifard Sharbiani { 1489abd4f750SMasoud Asgharifard Sharbiani .procname = "exception-trace", 1490abd4f750SMasoud Asgharifard Sharbiani .data = &show_unhandled_signals, 1491abd4f750SMasoud Asgharifard Sharbiani .maxlen = sizeof(int), 1492abd4f750SMasoud Asgharifard Sharbiani .mode = 0644, 1493abd4f750SMasoud Asgharifard Sharbiani .proc_handler = proc_dointvec 1494abd4f750SMasoud Asgharifard Sharbiani }, 1495abd4f750SMasoud Asgharifard Sharbiani #endif 1496b2be84dfSMasami Hiramatsu #if defined(CONFIG_OPTPROBES) 1497b2be84dfSMasami Hiramatsu { 1498b2be84dfSMasami Hiramatsu .procname = "kprobes-optimization", 1499b2be84dfSMasami Hiramatsu .data = &sysctl_kprobes_optimization, 1500b2be84dfSMasami Hiramatsu .maxlen = sizeof(int), 1501b2be84dfSMasami Hiramatsu .mode = 0644, 1502b2be84dfSMasami Hiramatsu .proc_handler = proc_kprobes_optimization_handler, 1503b2be84dfSMasami Hiramatsu .extra1 = &zero, 1504b2be84dfSMasami Hiramatsu .extra2 = &one, 1505b2be84dfSMasami Hiramatsu }, 1506b2be84dfSMasami Hiramatsu #endif 15076fce56ecSEric W. Biederman { } 15081da177e4SLinus Torvalds }; 15091da177e4SLinus Torvalds 1510d8217f07SEric W. Biederman static struct ctl_table dev_table[] = { 15116fce56ecSEric W. Biederman { } 15121da177e4SLinus Torvalds }; 15131da177e4SLinus Torvalds 1514330d57fbSAl Viro static DEFINE_SPINLOCK(sysctl_lock); 1515330d57fbSAl Viro 1516330d57fbSAl Viro /* called under sysctl_lock */ 1517330d57fbSAl Viro static int use_table(struct ctl_table_header *p) 1518330d57fbSAl Viro { 1519330d57fbSAl Viro if (unlikely(p->unregistering)) 1520330d57fbSAl Viro return 0; 1521330d57fbSAl Viro p->used++; 1522330d57fbSAl Viro return 1; 1523330d57fbSAl Viro } 1524330d57fbSAl Viro 1525330d57fbSAl Viro /* called under sysctl_lock */ 1526330d57fbSAl Viro static void unuse_table(struct ctl_table_header *p) 1527330d57fbSAl Viro { 1528330d57fbSAl Viro if (!--p->used) 1529330d57fbSAl Viro if (unlikely(p->unregistering)) 1530330d57fbSAl Viro complete(p->unregistering); 1531330d57fbSAl Viro } 1532330d57fbSAl Viro 1533330d57fbSAl Viro /* called under sysctl_lock, will reacquire if has to wait */ 1534330d57fbSAl Viro static void start_unregistering(struct ctl_table_header *p) 1535330d57fbSAl Viro { 1536330d57fbSAl Viro /* 1537330d57fbSAl Viro * if p->used is 0, nobody will ever touch that entry again; 1538330d57fbSAl Viro * we'll eliminate all paths to it before dropping sysctl_lock 1539330d57fbSAl Viro */ 1540330d57fbSAl Viro if (unlikely(p->used)) { 1541330d57fbSAl Viro struct completion wait; 1542330d57fbSAl Viro init_completion(&wait); 1543330d57fbSAl Viro p->unregistering = &wait; 1544330d57fbSAl Viro spin_unlock(&sysctl_lock); 1545330d57fbSAl Viro wait_for_completion(&wait); 1546330d57fbSAl Viro spin_lock(&sysctl_lock); 1547f7e6ced4SAl Viro } else { 1548f7e6ced4SAl Viro /* anything non-NULL; we'll never dereference it */ 1549f7e6ced4SAl Viro p->unregistering = ERR_PTR(-EINVAL); 1550330d57fbSAl Viro } 1551330d57fbSAl Viro /* 1552330d57fbSAl Viro * do not remove from the list until nobody holds it; walking the 1553330d57fbSAl Viro * list in do_sysctl() relies on that. 1554330d57fbSAl Viro */ 1555330d57fbSAl Viro list_del_init(&p->ctl_entry); 1556330d57fbSAl Viro } 1557330d57fbSAl Viro 1558f7e6ced4SAl Viro void sysctl_head_get(struct ctl_table_header *head) 1559f7e6ced4SAl Viro { 1560f7e6ced4SAl Viro spin_lock(&sysctl_lock); 1561f7e6ced4SAl Viro head->count++; 1562f7e6ced4SAl Viro spin_unlock(&sysctl_lock); 1563f7e6ced4SAl Viro } 1564f7e6ced4SAl Viro 1565f7e6ced4SAl Viro void sysctl_head_put(struct ctl_table_header *head) 1566f7e6ced4SAl Viro { 1567f7e6ced4SAl Viro spin_lock(&sysctl_lock); 1568f7e6ced4SAl Viro if (!--head->count) 1569f7e6ced4SAl Viro kfree(head); 1570f7e6ced4SAl Viro spin_unlock(&sysctl_lock); 1571f7e6ced4SAl Viro } 1572f7e6ced4SAl Viro 1573f7e6ced4SAl Viro struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head) 1574f7e6ced4SAl Viro { 1575f7e6ced4SAl Viro if (!head) 1576f7e6ced4SAl Viro BUG(); 1577f7e6ced4SAl Viro spin_lock(&sysctl_lock); 1578f7e6ced4SAl Viro if (!use_table(head)) 1579f7e6ced4SAl Viro head = ERR_PTR(-ENOENT); 1580f7e6ced4SAl Viro spin_unlock(&sysctl_lock); 1581f7e6ced4SAl Viro return head; 1582f7e6ced4SAl Viro } 1583f7e6ced4SAl Viro 1584805b5d5eSEric W. Biederman void sysctl_head_finish(struct ctl_table_header *head) 1585805b5d5eSEric W. Biederman { 1586805b5d5eSEric W. Biederman if (!head) 1587805b5d5eSEric W. Biederman return; 1588805b5d5eSEric W. Biederman spin_lock(&sysctl_lock); 1589805b5d5eSEric W. Biederman unuse_table(head); 1590805b5d5eSEric W. Biederman spin_unlock(&sysctl_lock); 1591805b5d5eSEric W. Biederman } 1592805b5d5eSEric W. Biederman 159373455092SAl Viro static struct ctl_table_set * 159473455092SAl Viro lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces) 159573455092SAl Viro { 159673455092SAl Viro struct ctl_table_set *set = &root->default_set; 159773455092SAl Viro if (root->lookup) 159873455092SAl Viro set = root->lookup(root, namespaces); 159973455092SAl Viro return set; 160073455092SAl Viro } 160173455092SAl Viro 1602e51b6ba0SEric W. Biederman static struct list_head * 1603e51b6ba0SEric W. Biederman lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces) 1604805b5d5eSEric W. Biederman { 160573455092SAl Viro struct ctl_table_set *set = lookup_header_set(root, namespaces); 160673455092SAl Viro return &set->list; 1607e51b6ba0SEric W. Biederman } 1608e51b6ba0SEric W. Biederman 1609e51b6ba0SEric W. Biederman struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces, 1610e51b6ba0SEric W. Biederman struct ctl_table_header *prev) 1611e51b6ba0SEric W. Biederman { 1612e51b6ba0SEric W. Biederman struct ctl_table_root *root; 1613e51b6ba0SEric W. Biederman struct list_head *header_list; 1614805b5d5eSEric W. Biederman struct ctl_table_header *head; 1615805b5d5eSEric W. Biederman struct list_head *tmp; 1616e51b6ba0SEric W. Biederman 1617805b5d5eSEric W. Biederman spin_lock(&sysctl_lock); 1618805b5d5eSEric W. Biederman if (prev) { 1619e51b6ba0SEric W. Biederman head = prev; 1620805b5d5eSEric W. Biederman tmp = &prev->ctl_entry; 1621805b5d5eSEric W. Biederman unuse_table(prev); 1622805b5d5eSEric W. Biederman goto next; 1623805b5d5eSEric W. Biederman } 1624805b5d5eSEric W. Biederman tmp = &root_table_header.ctl_entry; 1625805b5d5eSEric W. Biederman for (;;) { 1626805b5d5eSEric W. Biederman head = list_entry(tmp, struct ctl_table_header, ctl_entry); 1627805b5d5eSEric W. Biederman 1628805b5d5eSEric W. Biederman if (!use_table(head)) 1629805b5d5eSEric W. Biederman goto next; 1630805b5d5eSEric W. Biederman spin_unlock(&sysctl_lock); 1631805b5d5eSEric W. Biederman return head; 1632805b5d5eSEric W. Biederman next: 1633e51b6ba0SEric W. Biederman root = head->root; 1634805b5d5eSEric W. Biederman tmp = tmp->next; 1635e51b6ba0SEric W. Biederman header_list = lookup_header_list(root, namespaces); 1636e51b6ba0SEric W. Biederman if (tmp != header_list) 1637e51b6ba0SEric W. Biederman continue; 1638e51b6ba0SEric W. Biederman 1639e51b6ba0SEric W. Biederman do { 1640e51b6ba0SEric W. Biederman root = list_entry(root->root_list.next, 1641e51b6ba0SEric W. Biederman struct ctl_table_root, root_list); 1642e51b6ba0SEric W. Biederman if (root == &sysctl_table_root) 1643e51b6ba0SEric W. Biederman goto out; 1644e51b6ba0SEric W. Biederman header_list = lookup_header_list(root, namespaces); 1645e51b6ba0SEric W. Biederman } while (list_empty(header_list)); 1646e51b6ba0SEric W. Biederman tmp = header_list->next; 1647805b5d5eSEric W. Biederman } 1648e51b6ba0SEric W. Biederman out: 1649805b5d5eSEric W. Biederman spin_unlock(&sysctl_lock); 1650805b5d5eSEric W. Biederman return NULL; 1651805b5d5eSEric W. Biederman } 1652805b5d5eSEric W. Biederman 1653e51b6ba0SEric W. Biederman struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev) 1654e51b6ba0SEric W. Biederman { 1655e51b6ba0SEric W. Biederman return __sysctl_head_next(current->nsproxy, prev); 1656e51b6ba0SEric W. Biederman } 1657e51b6ba0SEric W. Biederman 1658e51b6ba0SEric W. Biederman void register_sysctl_root(struct ctl_table_root *root) 1659e51b6ba0SEric W. Biederman { 1660e51b6ba0SEric W. Biederman spin_lock(&sysctl_lock); 1661e51b6ba0SEric W. Biederman list_add_tail(&root->root_list, &sysctl_table_root.root_list); 1662e51b6ba0SEric W. Biederman spin_unlock(&sysctl_lock); 1663e51b6ba0SEric W. Biederman } 1664e51b6ba0SEric W. Biederman 16651da177e4SLinus Torvalds /* 16661ff007ebSEric W. Biederman * sysctl_perm does NOT grant the superuser all rights automatically, because 16671da177e4SLinus Torvalds * some sysctl variables are readonly even to root. 16681da177e4SLinus Torvalds */ 16691da177e4SLinus Torvalds 16701da177e4SLinus Torvalds static int test_perm(int mode, int op) 16711da177e4SLinus Torvalds { 167276aac0e9SDavid Howells if (!current_euid()) 16731da177e4SLinus Torvalds mode >>= 6; 16741da177e4SLinus Torvalds else if (in_egroup_p(0)) 16751da177e4SLinus Torvalds mode >>= 3; 1676e6305c43SAl Viro if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0) 16771da177e4SLinus Torvalds return 0; 16781da177e4SLinus Torvalds return -EACCES; 16791da177e4SLinus Torvalds } 16801da177e4SLinus Torvalds 1681d7321cd6SPavel Emelyanov int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op) 16821da177e4SLinus Torvalds { 16831da177e4SLinus Torvalds int error; 1684d7321cd6SPavel Emelyanov int mode; 1685d7321cd6SPavel Emelyanov 1686e6305c43SAl Viro error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC)); 16871da177e4SLinus Torvalds if (error) 16881da177e4SLinus Torvalds return error; 1689d7321cd6SPavel Emelyanov 1690d7321cd6SPavel Emelyanov if (root->permissions) 1691d7321cd6SPavel Emelyanov mode = root->permissions(root, current->nsproxy, table); 1692d7321cd6SPavel Emelyanov else 1693d7321cd6SPavel Emelyanov mode = table->mode; 1694d7321cd6SPavel Emelyanov 1695d7321cd6SPavel Emelyanov return test_perm(mode, op); 16961da177e4SLinus Torvalds } 16971da177e4SLinus Torvalds 1698d912b0ccSEric W. Biederman static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table) 1699d912b0ccSEric W. Biederman { 17002315ffa0SEric W. Biederman for (; table->procname; table++) { 1701d912b0ccSEric W. Biederman table->parent = parent; 1702d912b0ccSEric W. Biederman if (table->child) 1703d912b0ccSEric W. Biederman sysctl_set_parent(table, table->child); 1704d912b0ccSEric W. Biederman } 1705d912b0ccSEric W. Biederman } 1706d912b0ccSEric W. Biederman 1707d912b0ccSEric W. Biederman static __init int sysctl_init(void) 1708d912b0ccSEric W. Biederman { 1709d912b0ccSEric W. Biederman sysctl_set_parent(NULL, root_table); 171088f458e4SHolger Schurig #ifdef CONFIG_SYSCTL_SYSCALL_CHECK 1711b3bd3de6SAndi Kleen sysctl_check_table(current->nsproxy, root_table); 171288f458e4SHolger Schurig #endif 1713d912b0ccSEric W. Biederman return 0; 1714d912b0ccSEric W. Biederman } 1715d912b0ccSEric W. Biederman 1716d912b0ccSEric W. Biederman core_initcall(sysctl_init); 1717d912b0ccSEric W. Biederman 1718bfbcf034SAl Viro static struct ctl_table *is_branch_in(struct ctl_table *branch, 1719bfbcf034SAl Viro struct ctl_table *table) 1720ae7edeccSAl Viro { 1721ae7edeccSAl Viro struct ctl_table *p; 1722ae7edeccSAl Viro const char *s = branch->procname; 1723ae7edeccSAl Viro 1724ae7edeccSAl Viro /* branch should have named subdirectory as its first element */ 1725ae7edeccSAl Viro if (!s || !branch->child) 1726bfbcf034SAl Viro return NULL; 1727ae7edeccSAl Viro 1728ae7edeccSAl Viro /* ... and nothing else */ 17292315ffa0SEric W. Biederman if (branch[1].procname) 1730bfbcf034SAl Viro return NULL; 1731ae7edeccSAl Viro 1732ae7edeccSAl Viro /* table should contain subdirectory with the same name */ 17332315ffa0SEric W. Biederman for (p = table; p->procname; p++) { 1734ae7edeccSAl Viro if (!p->child) 1735ae7edeccSAl Viro continue; 1736ae7edeccSAl Viro if (p->procname && strcmp(p->procname, s) == 0) 1737bfbcf034SAl Viro return p; 1738ae7edeccSAl Viro } 1739bfbcf034SAl Viro return NULL; 1740ae7edeccSAl Viro } 1741ae7edeccSAl Viro 1742ae7edeccSAl Viro /* see if attaching q to p would be an improvement */ 1743ae7edeccSAl Viro static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q) 1744ae7edeccSAl Viro { 1745ae7edeccSAl Viro struct ctl_table *to = p->ctl_table, *by = q->ctl_table; 1746bfbcf034SAl Viro struct ctl_table *next; 1747ae7edeccSAl Viro int is_better = 0; 1748ae7edeccSAl Viro int not_in_parent = !p->attached_by; 1749ae7edeccSAl Viro 1750bfbcf034SAl Viro while ((next = is_branch_in(by, to)) != NULL) { 1751ae7edeccSAl Viro if (by == q->attached_by) 1752ae7edeccSAl Viro is_better = 1; 1753ae7edeccSAl Viro if (to == p->attached_by) 1754ae7edeccSAl Viro not_in_parent = 1; 1755ae7edeccSAl Viro by = by->child; 1756bfbcf034SAl Viro to = next->child; 1757ae7edeccSAl Viro } 1758ae7edeccSAl Viro 1759ae7edeccSAl Viro if (is_better && not_in_parent) { 1760ae7edeccSAl Viro q->attached_by = by; 1761ae7edeccSAl Viro q->attached_to = to; 1762ae7edeccSAl Viro q->parent = p; 1763ae7edeccSAl Viro } 1764ae7edeccSAl Viro } 1765ae7edeccSAl Viro 17661da177e4SLinus Torvalds /** 1767e51b6ba0SEric W. Biederman * __register_sysctl_paths - register a sysctl hierarchy 1768e51b6ba0SEric W. Biederman * @root: List of sysctl headers to register on 1769e51b6ba0SEric W. Biederman * @namespaces: Data to compute which lists of sysctl entries are visible 177029e796fdSEric W. Biederman * @path: The path to the directory the sysctl table is in. 17711da177e4SLinus Torvalds * @table: the top-level table structure 17721da177e4SLinus Torvalds * 17731da177e4SLinus Torvalds * Register a sysctl table hierarchy. @table should be a filled in ctl_table 177429e796fdSEric W. Biederman * array. A completely 0 filled entry terminates the table. 17751da177e4SLinus Torvalds * 1776d8217f07SEric W. Biederman * The members of the &struct ctl_table structure are used as follows: 17771da177e4SLinus Torvalds * 17781da177e4SLinus Torvalds * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not 17791da177e4SLinus Torvalds * enter a sysctl file 17801da177e4SLinus Torvalds * 17811da177e4SLinus Torvalds * data - a pointer to data for use by proc_handler 17821da177e4SLinus Torvalds * 17831da177e4SLinus Torvalds * maxlen - the maximum size in bytes of the data 17841da177e4SLinus Torvalds * 17851da177e4SLinus Torvalds * mode - the file permissions for the /proc/sys file, and for sysctl(2) 17861da177e4SLinus Torvalds * 17871da177e4SLinus Torvalds * child - a pointer to the child sysctl table if this entry is a directory, or 17881da177e4SLinus Torvalds * %NULL. 17891da177e4SLinus Torvalds * 17901da177e4SLinus Torvalds * proc_handler - the text handler routine (described below) 17911da177e4SLinus Torvalds * 17921da177e4SLinus Torvalds * de - for internal use by the sysctl routines 17931da177e4SLinus Torvalds * 17941da177e4SLinus Torvalds * extra1, extra2 - extra pointers usable by the proc handler routines 17951da177e4SLinus Torvalds * 17961da177e4SLinus Torvalds * Leaf nodes in the sysctl tree will be represented by a single file 17971da177e4SLinus Torvalds * under /proc; non-leaf nodes will be represented by directories. 17981da177e4SLinus Torvalds * 17991da177e4SLinus Torvalds * sysctl(2) can automatically manage read and write requests through 18001da177e4SLinus Torvalds * the sysctl table. The data and maxlen fields of the ctl_table 18011da177e4SLinus Torvalds * struct enable minimal validation of the values being written to be 18021da177e4SLinus Torvalds * performed, and the mode field allows minimal authentication. 18031da177e4SLinus Torvalds * 18041da177e4SLinus Torvalds * There must be a proc_handler routine for any terminal nodes 18051da177e4SLinus Torvalds * mirrored under /proc/sys (non-terminals are handled by a built-in 18061da177e4SLinus Torvalds * directory handler). Several default handlers are available to 18071da177e4SLinus Torvalds * cover common cases - 18081da177e4SLinus Torvalds * 18091da177e4SLinus Torvalds * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(), 18101da177e4SLinus Torvalds * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(), 18111da177e4SLinus Torvalds * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax() 18121da177e4SLinus Torvalds * 18131da177e4SLinus Torvalds * It is the handler's job to read the input buffer from user memory 18141da177e4SLinus Torvalds * and process it. The handler should return 0 on success. 18151da177e4SLinus Torvalds * 18161da177e4SLinus Torvalds * This routine returns %NULL on a failure to register, and a pointer 18171da177e4SLinus Torvalds * to the table header on success. 18181da177e4SLinus Torvalds */ 1819e51b6ba0SEric W. Biederman struct ctl_table_header *__register_sysctl_paths( 1820e51b6ba0SEric W. Biederman struct ctl_table_root *root, 1821e51b6ba0SEric W. Biederman struct nsproxy *namespaces, 1822e51b6ba0SEric W. Biederman const struct ctl_path *path, struct ctl_table *table) 18231da177e4SLinus Torvalds { 182429e796fdSEric W. Biederman struct ctl_table_header *header; 182529e796fdSEric W. Biederman struct ctl_table *new, **prevp; 182629e796fdSEric W. Biederman unsigned int n, npath; 1827ae7edeccSAl Viro struct ctl_table_set *set; 182829e796fdSEric W. Biederman 182929e796fdSEric W. Biederman /* Count the path components */ 18302315ffa0SEric W. Biederman for (npath = 0; path[npath].procname; ++npath) 183129e796fdSEric W. Biederman ; 183229e796fdSEric W. Biederman 183329e796fdSEric W. Biederman /* 183429e796fdSEric W. Biederman * For each path component, allocate a 2-element ctl_table array. 183529e796fdSEric W. Biederman * The first array element will be filled with the sysctl entry 18362315ffa0SEric W. Biederman * for this, the second will be the sentinel (procname == 0). 183729e796fdSEric W. Biederman * 183829e796fdSEric W. Biederman * We allocate everything in one go so that we don't have to 183929e796fdSEric W. Biederman * worry about freeing additional memory in unregister_sysctl_table. 184029e796fdSEric W. Biederman */ 184129e796fdSEric W. Biederman header = kzalloc(sizeof(struct ctl_table_header) + 184229e796fdSEric W. Biederman (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL); 184329e796fdSEric W. Biederman if (!header) 18441da177e4SLinus Torvalds return NULL; 184529e796fdSEric W. Biederman 184629e796fdSEric W. Biederman new = (struct ctl_table *) (header + 1); 184729e796fdSEric W. Biederman 184829e796fdSEric W. Biederman /* Now connect the dots */ 184929e796fdSEric W. Biederman prevp = &header->ctl_table; 185029e796fdSEric W. Biederman for (n = 0; n < npath; ++n, ++path) { 185129e796fdSEric W. Biederman /* Copy the procname */ 185229e796fdSEric W. Biederman new->procname = path->procname; 185329e796fdSEric W. Biederman new->mode = 0555; 185429e796fdSEric W. Biederman 185529e796fdSEric W. Biederman *prevp = new; 185629e796fdSEric W. Biederman prevp = &new->child; 185729e796fdSEric W. Biederman 185829e796fdSEric W. Biederman new += 2; 185929e796fdSEric W. Biederman } 186029e796fdSEric W. Biederman *prevp = table; 186123eb06deSEric W. Biederman header->ctl_table_arg = table; 186229e796fdSEric W. Biederman 186329e796fdSEric W. Biederman INIT_LIST_HEAD(&header->ctl_entry); 186429e796fdSEric W. Biederman header->used = 0; 186529e796fdSEric W. Biederman header->unregistering = NULL; 1866e51b6ba0SEric W. Biederman header->root = root; 186729e796fdSEric W. Biederman sysctl_set_parent(NULL, header->ctl_table); 1868f7e6ced4SAl Viro header->count = 1; 186988f458e4SHolger Schurig #ifdef CONFIG_SYSCTL_SYSCALL_CHECK 1870e51b6ba0SEric W. Biederman if (sysctl_check_table(namespaces, header->ctl_table)) { 187129e796fdSEric W. Biederman kfree(header); 1872fc6cd25bSEric W. Biederman return NULL; 1873fc6cd25bSEric W. Biederman } 187488f458e4SHolger Schurig #endif 1875330d57fbSAl Viro spin_lock(&sysctl_lock); 187673455092SAl Viro header->set = lookup_header_set(root, namespaces); 1877ae7edeccSAl Viro header->attached_by = header->ctl_table; 1878ae7edeccSAl Viro header->attached_to = root_table; 1879ae7edeccSAl Viro header->parent = &root_table_header; 1880ae7edeccSAl Viro for (set = header->set; set; set = set->parent) { 1881ae7edeccSAl Viro struct ctl_table_header *p; 1882ae7edeccSAl Viro list_for_each_entry(p, &set->list, ctl_entry) { 1883ae7edeccSAl Viro if (p->unregistering) 1884ae7edeccSAl Viro continue; 1885ae7edeccSAl Viro try_attach(p, header); 1886ae7edeccSAl Viro } 1887ae7edeccSAl Viro } 1888ae7edeccSAl Viro header->parent->count++; 188973455092SAl Viro list_add_tail(&header->ctl_entry, &header->set->list); 1890330d57fbSAl Viro spin_unlock(&sysctl_lock); 189129e796fdSEric W. Biederman 189229e796fdSEric W. Biederman return header; 189329e796fdSEric W. Biederman } 189429e796fdSEric W. Biederman 189529e796fdSEric W. Biederman /** 1896e51b6ba0SEric W. Biederman * register_sysctl_table_path - register a sysctl table hierarchy 1897e51b6ba0SEric W. Biederman * @path: The path to the directory the sysctl table is in. 1898e51b6ba0SEric W. Biederman * @table: the top-level table structure 1899e51b6ba0SEric W. Biederman * 1900e51b6ba0SEric W. Biederman * Register a sysctl table hierarchy. @table should be a filled in ctl_table 1901e51b6ba0SEric W. Biederman * array. A completely 0 filled entry terminates the table. 1902e51b6ba0SEric W. Biederman * 1903e51b6ba0SEric W. Biederman * See __register_sysctl_paths for more details. 1904e51b6ba0SEric W. Biederman */ 1905e51b6ba0SEric W. Biederman struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, 1906e51b6ba0SEric W. Biederman struct ctl_table *table) 1907e51b6ba0SEric W. Biederman { 1908e51b6ba0SEric W. Biederman return __register_sysctl_paths(&sysctl_table_root, current->nsproxy, 1909e51b6ba0SEric W. Biederman path, table); 1910e51b6ba0SEric W. Biederman } 1911e51b6ba0SEric W. Biederman 1912e51b6ba0SEric W. Biederman /** 191329e796fdSEric W. Biederman * register_sysctl_table - register a sysctl table hierarchy 191429e796fdSEric W. Biederman * @table: the top-level table structure 191529e796fdSEric W. Biederman * 191629e796fdSEric W. Biederman * Register a sysctl table hierarchy. @table should be a filled in ctl_table 191729e796fdSEric W. Biederman * array. A completely 0 filled entry terminates the table. 191829e796fdSEric W. Biederman * 191929e796fdSEric W. Biederman * See register_sysctl_paths for more details. 192029e796fdSEric W. Biederman */ 192129e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_table(struct ctl_table *table) 192229e796fdSEric W. Biederman { 192329e796fdSEric W. Biederman static const struct ctl_path null_path[] = { {} }; 192429e796fdSEric W. Biederman 192529e796fdSEric W. Biederman return register_sysctl_paths(null_path, table); 19261da177e4SLinus Torvalds } 19271da177e4SLinus Torvalds 19281da177e4SLinus Torvalds /** 19291da177e4SLinus Torvalds * unregister_sysctl_table - unregister a sysctl table hierarchy 19301da177e4SLinus Torvalds * @header: the header returned from register_sysctl_table 19311da177e4SLinus Torvalds * 19321da177e4SLinus Torvalds * Unregisters the sysctl table and all children. proc entries may not 19331da177e4SLinus Torvalds * actually be removed until they are no longer used by anyone. 19341da177e4SLinus Torvalds */ 19351da177e4SLinus Torvalds void unregister_sysctl_table(struct ctl_table_header * header) 19361da177e4SLinus Torvalds { 1937330d57fbSAl Viro might_sleep(); 1938f1dad166SPavel Emelyanov 1939f1dad166SPavel Emelyanov if (header == NULL) 1940f1dad166SPavel Emelyanov return; 1941f1dad166SPavel Emelyanov 1942330d57fbSAl Viro spin_lock(&sysctl_lock); 1943330d57fbSAl Viro start_unregistering(header); 1944ae7edeccSAl Viro if (!--header->parent->count) { 1945ae7edeccSAl Viro WARN_ON(1); 1946ae7edeccSAl Viro kfree(header->parent); 1947ae7edeccSAl Viro } 1948f7e6ced4SAl Viro if (!--header->count) 19491da177e4SLinus Torvalds kfree(header); 1950f7e6ced4SAl Viro spin_unlock(&sysctl_lock); 19511da177e4SLinus Torvalds } 19521da177e4SLinus Torvalds 19539043476fSAl Viro int sysctl_is_seen(struct ctl_table_header *p) 19549043476fSAl Viro { 19559043476fSAl Viro struct ctl_table_set *set = p->set; 19569043476fSAl Viro int res; 19579043476fSAl Viro spin_lock(&sysctl_lock); 19589043476fSAl Viro if (p->unregistering) 19599043476fSAl Viro res = 0; 19609043476fSAl Viro else if (!set->is_seen) 19619043476fSAl Viro res = 1; 19629043476fSAl Viro else 19639043476fSAl Viro res = set->is_seen(set); 19649043476fSAl Viro spin_unlock(&sysctl_lock); 19659043476fSAl Viro return res; 19669043476fSAl Viro } 19679043476fSAl Viro 196873455092SAl Viro void setup_sysctl_set(struct ctl_table_set *p, 196973455092SAl Viro struct ctl_table_set *parent, 197073455092SAl Viro int (*is_seen)(struct ctl_table_set *)) 197173455092SAl Viro { 197273455092SAl Viro INIT_LIST_HEAD(&p->list); 197373455092SAl Viro p->parent = parent ? parent : &sysctl_table_root.default_set; 197473455092SAl Viro p->is_seen = is_seen; 197573455092SAl Viro } 197673455092SAl Viro 1977b89a8171SEric W. Biederman #else /* !CONFIG_SYSCTL */ 1978d8217f07SEric W. Biederman struct ctl_table_header *register_sysctl_table(struct ctl_table * table) 1979b89a8171SEric W. Biederman { 1980b89a8171SEric W. Biederman return NULL; 1981b89a8171SEric W. Biederman } 1982b89a8171SEric W. Biederman 198329e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, 198429e796fdSEric W. Biederman struct ctl_table *table) 198529e796fdSEric W. Biederman { 198629e796fdSEric W. Biederman return NULL; 198729e796fdSEric W. Biederman } 198829e796fdSEric W. Biederman 1989b89a8171SEric W. Biederman void unregister_sysctl_table(struct ctl_table_header * table) 1990b89a8171SEric W. Biederman { 1991b89a8171SEric W. Biederman } 1992b89a8171SEric W. Biederman 199373455092SAl Viro void setup_sysctl_set(struct ctl_table_set *p, 199473455092SAl Viro struct ctl_table_set *parent, 199573455092SAl Viro int (*is_seen)(struct ctl_table_set *)) 199673455092SAl Viro { 199773455092SAl Viro } 199873455092SAl Viro 1999f7e6ced4SAl Viro void sysctl_head_put(struct ctl_table_header *head) 2000f7e6ced4SAl Viro { 2001f7e6ced4SAl Viro } 2002f7e6ced4SAl Viro 2003b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL */ 2004b89a8171SEric W. Biederman 20051da177e4SLinus Torvalds /* 20061da177e4SLinus Torvalds * /proc/sys support 20071da177e4SLinus Torvalds */ 20081da177e4SLinus Torvalds 2009b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL 20101da177e4SLinus Torvalds 2011b1ba4dddSAdrian Bunk static int _proc_do_string(void* data, int maxlen, int write, 20128d65af78SAlexey Dobriyan void __user *buffer, 2013b1ba4dddSAdrian Bunk size_t *lenp, loff_t *ppos) 2014f5dd3d6fSSam Vilain { 2015f5dd3d6fSSam Vilain size_t len; 2016f5dd3d6fSSam Vilain char __user *p; 2017f5dd3d6fSSam Vilain char c; 2018f5dd3d6fSSam Vilain 20198d060877SOleg Nesterov if (!data || !maxlen || !*lenp) { 2020f5dd3d6fSSam Vilain *lenp = 0; 2021f5dd3d6fSSam Vilain return 0; 2022f5dd3d6fSSam Vilain } 2023f5dd3d6fSSam Vilain 2024f5dd3d6fSSam Vilain if (write) { 2025f5dd3d6fSSam Vilain len = 0; 2026f5dd3d6fSSam Vilain p = buffer; 2027f5dd3d6fSSam Vilain while (len < *lenp) { 2028f5dd3d6fSSam Vilain if (get_user(c, p++)) 2029f5dd3d6fSSam Vilain return -EFAULT; 2030f5dd3d6fSSam Vilain if (c == 0 || c == '\n') 2031f5dd3d6fSSam Vilain break; 2032f5dd3d6fSSam Vilain len++; 2033f5dd3d6fSSam Vilain } 2034f5dd3d6fSSam Vilain if (len >= maxlen) 2035f5dd3d6fSSam Vilain len = maxlen-1; 2036f5dd3d6fSSam Vilain if(copy_from_user(data, buffer, len)) 2037f5dd3d6fSSam Vilain return -EFAULT; 2038f5dd3d6fSSam Vilain ((char *) data)[len] = 0; 2039f5dd3d6fSSam Vilain *ppos += *lenp; 2040f5dd3d6fSSam Vilain } else { 2041f5dd3d6fSSam Vilain len = strlen(data); 2042f5dd3d6fSSam Vilain if (len > maxlen) 2043f5dd3d6fSSam Vilain len = maxlen; 20448d060877SOleg Nesterov 20458d060877SOleg Nesterov if (*ppos > len) { 20468d060877SOleg Nesterov *lenp = 0; 20478d060877SOleg Nesterov return 0; 20488d060877SOleg Nesterov } 20498d060877SOleg Nesterov 20508d060877SOleg Nesterov data += *ppos; 20518d060877SOleg Nesterov len -= *ppos; 20528d060877SOleg Nesterov 2053f5dd3d6fSSam Vilain if (len > *lenp) 2054f5dd3d6fSSam Vilain len = *lenp; 2055f5dd3d6fSSam Vilain if (len) 2056f5dd3d6fSSam Vilain if(copy_to_user(buffer, data, len)) 2057f5dd3d6fSSam Vilain return -EFAULT; 2058f5dd3d6fSSam Vilain if (len < *lenp) { 2059f5dd3d6fSSam Vilain if(put_user('\n', ((char __user *) buffer) + len)) 2060f5dd3d6fSSam Vilain return -EFAULT; 2061f5dd3d6fSSam Vilain len++; 2062f5dd3d6fSSam Vilain } 2063f5dd3d6fSSam Vilain *lenp = len; 2064f5dd3d6fSSam Vilain *ppos += len; 2065f5dd3d6fSSam Vilain } 2066f5dd3d6fSSam Vilain return 0; 2067f5dd3d6fSSam Vilain } 2068f5dd3d6fSSam Vilain 20691da177e4SLinus Torvalds /** 20701da177e4SLinus Torvalds * proc_dostring - read a string sysctl 20711da177e4SLinus Torvalds * @table: the sysctl table 20721da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 20731da177e4SLinus Torvalds * @buffer: the user buffer 20741da177e4SLinus Torvalds * @lenp: the size of the user buffer 20751da177e4SLinus Torvalds * @ppos: file position 20761da177e4SLinus Torvalds * 20771da177e4SLinus Torvalds * Reads/writes a string from/to the user buffer. If the kernel 20781da177e4SLinus Torvalds * buffer provided is not large enough to hold the string, the 20791da177e4SLinus Torvalds * string is truncated. The copied string is %NULL-terminated. 20801da177e4SLinus Torvalds * If the string is being read by the user process, it is copied 20811da177e4SLinus Torvalds * and a newline '\n' is added. It is truncated if the buffer is 20821da177e4SLinus Torvalds * not large enough. 20831da177e4SLinus Torvalds * 20841da177e4SLinus Torvalds * Returns 0 on success. 20851da177e4SLinus Torvalds */ 20868d65af78SAlexey Dobriyan int proc_dostring(struct ctl_table *table, int write, 20871da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 20881da177e4SLinus Torvalds { 20898d65af78SAlexey Dobriyan return _proc_do_string(table->data, table->maxlen, write, 2090f5dd3d6fSSam Vilain buffer, lenp, ppos); 20911da177e4SLinus Torvalds } 20921da177e4SLinus Torvalds 209300b7c339SAmerigo Wang static size_t proc_skip_spaces(char **buf) 209400b7c339SAmerigo Wang { 209500b7c339SAmerigo Wang size_t ret; 209600b7c339SAmerigo Wang char *tmp = skip_spaces(*buf); 209700b7c339SAmerigo Wang ret = tmp - *buf; 209800b7c339SAmerigo Wang *buf = tmp; 209900b7c339SAmerigo Wang return ret; 210000b7c339SAmerigo Wang } 21011da177e4SLinus Torvalds 21029f977fb7SOctavian Purdila static void proc_skip_char(char **buf, size_t *size, const char v) 21039f977fb7SOctavian Purdila { 21049f977fb7SOctavian Purdila while (*size) { 21059f977fb7SOctavian Purdila if (**buf != v) 21069f977fb7SOctavian Purdila break; 21079f977fb7SOctavian Purdila (*size)--; 21089f977fb7SOctavian Purdila (*buf)++; 21099f977fb7SOctavian Purdila } 21109f977fb7SOctavian Purdila } 21119f977fb7SOctavian Purdila 211200b7c339SAmerigo Wang #define TMPBUFLEN 22 211300b7c339SAmerigo Wang /** 21140fc377bdSRandy Dunlap * proc_get_long - reads an ASCII formatted integer from a user buffer 211500b7c339SAmerigo Wang * 21160fc377bdSRandy Dunlap * @buf: a kernel buffer 21170fc377bdSRandy Dunlap * @size: size of the kernel buffer 21180fc377bdSRandy Dunlap * @val: this is where the number will be stored 21190fc377bdSRandy Dunlap * @neg: set to %TRUE if number is negative 21200fc377bdSRandy Dunlap * @perm_tr: a vector which contains the allowed trailers 21210fc377bdSRandy Dunlap * @perm_tr_len: size of the perm_tr vector 21220fc377bdSRandy Dunlap * @tr: pointer to store the trailer character 212300b7c339SAmerigo Wang * 21240fc377bdSRandy Dunlap * In case of success %0 is returned and @buf and @size are updated with 21250fc377bdSRandy Dunlap * the amount of bytes read. If @tr is non-NULL and a trailing 21260fc377bdSRandy Dunlap * character exists (size is non-zero after returning from this 21270fc377bdSRandy Dunlap * function), @tr is updated with the trailing character. 212800b7c339SAmerigo Wang */ 212900b7c339SAmerigo Wang static int proc_get_long(char **buf, size_t *size, 213000b7c339SAmerigo Wang unsigned long *val, bool *neg, 213100b7c339SAmerigo Wang const char *perm_tr, unsigned perm_tr_len, char *tr) 213200b7c339SAmerigo Wang { 213300b7c339SAmerigo Wang int len; 213400b7c339SAmerigo Wang char *p, tmp[TMPBUFLEN]; 213500b7c339SAmerigo Wang 213600b7c339SAmerigo Wang if (!*size) 213700b7c339SAmerigo Wang return -EINVAL; 213800b7c339SAmerigo Wang 213900b7c339SAmerigo Wang len = *size; 214000b7c339SAmerigo Wang if (len > TMPBUFLEN - 1) 214100b7c339SAmerigo Wang len = TMPBUFLEN - 1; 214200b7c339SAmerigo Wang 214300b7c339SAmerigo Wang memcpy(tmp, *buf, len); 214400b7c339SAmerigo Wang 214500b7c339SAmerigo Wang tmp[len] = 0; 214600b7c339SAmerigo Wang p = tmp; 214700b7c339SAmerigo Wang if (*p == '-' && *size > 1) { 214800b7c339SAmerigo Wang *neg = true; 214900b7c339SAmerigo Wang p++; 215000b7c339SAmerigo Wang } else 215100b7c339SAmerigo Wang *neg = false; 215200b7c339SAmerigo Wang if (!isdigit(*p)) 215300b7c339SAmerigo Wang return -EINVAL; 215400b7c339SAmerigo Wang 215500b7c339SAmerigo Wang *val = simple_strtoul(p, &p, 0); 215600b7c339SAmerigo Wang 215700b7c339SAmerigo Wang len = p - tmp; 215800b7c339SAmerigo Wang 215900b7c339SAmerigo Wang /* We don't know if the next char is whitespace thus we may accept 216000b7c339SAmerigo Wang * invalid integers (e.g. 1234...a) or two integers instead of one 216100b7c339SAmerigo Wang * (e.g. 123...1). So lets not allow such large numbers. */ 216200b7c339SAmerigo Wang if (len == TMPBUFLEN - 1) 216300b7c339SAmerigo Wang return -EINVAL; 216400b7c339SAmerigo Wang 216500b7c339SAmerigo Wang if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len)) 216600b7c339SAmerigo Wang return -EINVAL; 216700b7c339SAmerigo Wang 216800b7c339SAmerigo Wang if (tr && (len < *size)) 216900b7c339SAmerigo Wang *tr = *p; 217000b7c339SAmerigo Wang 217100b7c339SAmerigo Wang *buf += len; 217200b7c339SAmerigo Wang *size -= len; 217300b7c339SAmerigo Wang 217400b7c339SAmerigo Wang return 0; 217500b7c339SAmerigo Wang } 217600b7c339SAmerigo Wang 217700b7c339SAmerigo Wang /** 21780fc377bdSRandy Dunlap * proc_put_long - converts an integer to a decimal ASCII formatted string 217900b7c339SAmerigo Wang * 21800fc377bdSRandy Dunlap * @buf: the user buffer 21810fc377bdSRandy Dunlap * @size: the size of the user buffer 21820fc377bdSRandy Dunlap * @val: the integer to be converted 21830fc377bdSRandy Dunlap * @neg: sign of the number, %TRUE for negative 218400b7c339SAmerigo Wang * 21850fc377bdSRandy Dunlap * In case of success %0 is returned and @buf and @size are updated with 21860fc377bdSRandy Dunlap * the amount of bytes written. 218700b7c339SAmerigo Wang */ 218800b7c339SAmerigo Wang static int proc_put_long(void __user **buf, size_t *size, unsigned long val, 218900b7c339SAmerigo Wang bool neg) 219000b7c339SAmerigo Wang { 219100b7c339SAmerigo Wang int len; 219200b7c339SAmerigo Wang char tmp[TMPBUFLEN], *p = tmp; 219300b7c339SAmerigo Wang 219400b7c339SAmerigo Wang sprintf(p, "%s%lu", neg ? "-" : "", val); 219500b7c339SAmerigo Wang len = strlen(tmp); 219600b7c339SAmerigo Wang if (len > *size) 219700b7c339SAmerigo Wang len = *size; 219800b7c339SAmerigo Wang if (copy_to_user(*buf, tmp, len)) 219900b7c339SAmerigo Wang return -EFAULT; 220000b7c339SAmerigo Wang *size -= len; 220100b7c339SAmerigo Wang *buf += len; 220200b7c339SAmerigo Wang return 0; 220300b7c339SAmerigo Wang } 220400b7c339SAmerigo Wang #undef TMPBUFLEN 220500b7c339SAmerigo Wang 220600b7c339SAmerigo Wang static int proc_put_char(void __user **buf, size_t *size, char c) 220700b7c339SAmerigo Wang { 220800b7c339SAmerigo Wang if (*size) { 220900b7c339SAmerigo Wang char __user **buffer = (char __user **)buf; 221000b7c339SAmerigo Wang if (put_user(c, *buffer)) 221100b7c339SAmerigo Wang return -EFAULT; 221200b7c339SAmerigo Wang (*size)--, (*buffer)++; 221300b7c339SAmerigo Wang *buf = *buffer; 221400b7c339SAmerigo Wang } 221500b7c339SAmerigo Wang return 0; 221600b7c339SAmerigo Wang } 221700b7c339SAmerigo Wang 221800b7c339SAmerigo Wang static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, 22191da177e4SLinus Torvalds int *valp, 22201da177e4SLinus Torvalds int write, void *data) 22211da177e4SLinus Torvalds { 22221da177e4SLinus Torvalds if (write) { 22231da177e4SLinus Torvalds *valp = *negp ? -*lvalp : *lvalp; 22241da177e4SLinus Torvalds } else { 22251da177e4SLinus Torvalds int val = *valp; 22261da177e4SLinus Torvalds if (val < 0) { 222700b7c339SAmerigo Wang *negp = true; 22281da177e4SLinus Torvalds *lvalp = (unsigned long)-val; 22291da177e4SLinus Torvalds } else { 223000b7c339SAmerigo Wang *negp = false; 22311da177e4SLinus Torvalds *lvalp = (unsigned long)val; 22321da177e4SLinus Torvalds } 22331da177e4SLinus Torvalds } 22341da177e4SLinus Torvalds return 0; 22351da177e4SLinus Torvalds } 22361da177e4SLinus Torvalds 223700b7c339SAmerigo Wang static const char proc_wspace_sep[] = { ' ', '\t', '\n' }; 223800b7c339SAmerigo Wang 2239d8217f07SEric W. Biederman static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table, 22408d65af78SAlexey Dobriyan int write, void __user *buffer, 2241fcfbd547SKirill Korotaev size_t *lenp, loff_t *ppos, 224200b7c339SAmerigo Wang int (*conv)(bool *negp, unsigned long *lvalp, int *valp, 22431da177e4SLinus Torvalds int write, void *data), 22441da177e4SLinus Torvalds void *data) 22451da177e4SLinus Torvalds { 224600b7c339SAmerigo Wang int *i, vleft, first = 1, err = 0; 224700b7c339SAmerigo Wang unsigned long page = 0; 224800b7c339SAmerigo Wang size_t left; 224900b7c339SAmerigo Wang char *kbuf; 22501da177e4SLinus Torvalds 225100b7c339SAmerigo Wang if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) { 22521da177e4SLinus Torvalds *lenp = 0; 22531da177e4SLinus Torvalds return 0; 22541da177e4SLinus Torvalds } 22551da177e4SLinus Torvalds 2256fcfbd547SKirill Korotaev i = (int *) tbl_data; 22571da177e4SLinus Torvalds vleft = table->maxlen / sizeof(*i); 22581da177e4SLinus Torvalds left = *lenp; 22591da177e4SLinus Torvalds 22601da177e4SLinus Torvalds if (!conv) 22611da177e4SLinus Torvalds conv = do_proc_dointvec_conv; 22621da177e4SLinus Torvalds 226300b7c339SAmerigo Wang if (write) { 226400b7c339SAmerigo Wang if (left > PAGE_SIZE - 1) 226500b7c339SAmerigo Wang left = PAGE_SIZE - 1; 226600b7c339SAmerigo Wang page = __get_free_page(GFP_TEMPORARY); 226700b7c339SAmerigo Wang kbuf = (char *) page; 226800b7c339SAmerigo Wang if (!kbuf) 226900b7c339SAmerigo Wang return -ENOMEM; 227000b7c339SAmerigo Wang if (copy_from_user(kbuf, buffer, left)) { 227100b7c339SAmerigo Wang err = -EFAULT; 227200b7c339SAmerigo Wang goto free; 227300b7c339SAmerigo Wang } 227400b7c339SAmerigo Wang kbuf[left] = 0; 227500b7c339SAmerigo Wang } 227600b7c339SAmerigo Wang 22771da177e4SLinus Torvalds for (; left && vleft--; i++, first=0) { 227800b7c339SAmerigo Wang unsigned long lval; 227900b7c339SAmerigo Wang bool neg; 228000b7c339SAmerigo Wang 22811da177e4SLinus Torvalds if (write) { 228200b7c339SAmerigo Wang left -= proc_skip_spaces(&kbuf); 228300b7c339SAmerigo Wang 2284563b0467SJ. R. Okajima if (!left) 2285563b0467SJ. R. Okajima break; 228600b7c339SAmerigo Wang err = proc_get_long(&kbuf, &left, &lval, &neg, 228700b7c339SAmerigo Wang proc_wspace_sep, 228800b7c339SAmerigo Wang sizeof(proc_wspace_sep), NULL); 228900b7c339SAmerigo Wang if (err) 22901da177e4SLinus Torvalds break; 229100b7c339SAmerigo Wang if (conv(&neg, &lval, i, 1, data)) { 229200b7c339SAmerigo Wang err = -EINVAL; 229300b7c339SAmerigo Wang break; 22941da177e4SLinus Torvalds } 22951da177e4SLinus Torvalds } else { 229600b7c339SAmerigo Wang if (conv(&neg, &lval, i, 0, data)) { 229700b7c339SAmerigo Wang err = -EINVAL; 229800b7c339SAmerigo Wang break; 229900b7c339SAmerigo Wang } 23001da177e4SLinus Torvalds if (!first) 230100b7c339SAmerigo Wang err = proc_put_char(&buffer, &left, '\t'); 230200b7c339SAmerigo Wang if (err) 23031da177e4SLinus Torvalds break; 230400b7c339SAmerigo Wang err = proc_put_long(&buffer, &left, lval, neg); 230500b7c339SAmerigo Wang if (err) 230600b7c339SAmerigo Wang break; 23071da177e4SLinus Torvalds } 23081da177e4SLinus Torvalds } 23091da177e4SLinus Torvalds 231000b7c339SAmerigo Wang if (!write && !first && left && !err) 231100b7c339SAmerigo Wang err = proc_put_char(&buffer, &left, '\n'); 2312563b0467SJ. R. Okajima if (write && !err && left) 231300b7c339SAmerigo Wang left -= proc_skip_spaces(&kbuf); 231400b7c339SAmerigo Wang free: 23151da177e4SLinus Torvalds if (write) { 231600b7c339SAmerigo Wang free_page(page); 231700b7c339SAmerigo Wang if (first) 231800b7c339SAmerigo Wang return err ? : -EINVAL; 23191da177e4SLinus Torvalds } 23201da177e4SLinus Torvalds *lenp -= left; 23211da177e4SLinus Torvalds *ppos += *lenp; 232200b7c339SAmerigo Wang return err; 23231da177e4SLinus Torvalds } 23241da177e4SLinus Torvalds 23258d65af78SAlexey Dobriyan static int do_proc_dointvec(struct ctl_table *table, int write, 2326fcfbd547SKirill Korotaev void __user *buffer, size_t *lenp, loff_t *ppos, 232700b7c339SAmerigo Wang int (*conv)(bool *negp, unsigned long *lvalp, int *valp, 2328fcfbd547SKirill Korotaev int write, void *data), 2329fcfbd547SKirill Korotaev void *data) 2330fcfbd547SKirill Korotaev { 23318d65af78SAlexey Dobriyan return __do_proc_dointvec(table->data, table, write, 2332fcfbd547SKirill Korotaev buffer, lenp, ppos, conv, data); 2333fcfbd547SKirill Korotaev } 2334fcfbd547SKirill Korotaev 23351da177e4SLinus Torvalds /** 23361da177e4SLinus Torvalds * proc_dointvec - read a vector of integers 23371da177e4SLinus Torvalds * @table: the sysctl table 23381da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 23391da177e4SLinus Torvalds * @buffer: the user buffer 23401da177e4SLinus Torvalds * @lenp: the size of the user buffer 23411da177e4SLinus Torvalds * @ppos: file position 23421da177e4SLinus Torvalds * 23431da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 23441da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 23451da177e4SLinus Torvalds * 23461da177e4SLinus Torvalds * Returns 0 on success. 23471da177e4SLinus Torvalds */ 23488d65af78SAlexey Dobriyan int proc_dointvec(struct ctl_table *table, int write, 23491da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 23501da177e4SLinus Torvalds { 23518d65af78SAlexey Dobriyan return do_proc_dointvec(table,write,buffer,lenp,ppos, 23521da177e4SLinus Torvalds NULL,NULL); 23531da177e4SLinus Torvalds } 23541da177e4SLinus Torvalds 235534f5a398STheodore Ts'o /* 235634f5a398STheodore Ts'o * Taint values can only be increased 235725ddbb18SAndi Kleen * This means we can safely use a temporary. 235834f5a398STheodore Ts'o */ 23598d65af78SAlexey Dobriyan static int proc_taint(struct ctl_table *table, int write, 236034f5a398STheodore Ts'o void __user *buffer, size_t *lenp, loff_t *ppos) 236134f5a398STheodore Ts'o { 236225ddbb18SAndi Kleen struct ctl_table t; 236325ddbb18SAndi Kleen unsigned long tmptaint = get_taint(); 236425ddbb18SAndi Kleen int err; 236534f5a398STheodore Ts'o 236691fcd412SBastian Blank if (write && !capable(CAP_SYS_ADMIN)) 236734f5a398STheodore Ts'o return -EPERM; 236834f5a398STheodore Ts'o 236925ddbb18SAndi Kleen t = *table; 237025ddbb18SAndi Kleen t.data = &tmptaint; 23718d65af78SAlexey Dobriyan err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos); 237225ddbb18SAndi Kleen if (err < 0) 237325ddbb18SAndi Kleen return err; 237425ddbb18SAndi Kleen 237525ddbb18SAndi Kleen if (write) { 237625ddbb18SAndi Kleen /* 237725ddbb18SAndi Kleen * Poor man's atomic or. Not worth adding a primitive 237825ddbb18SAndi Kleen * to everyone's atomic.h for this 237925ddbb18SAndi Kleen */ 238025ddbb18SAndi Kleen int i; 238125ddbb18SAndi Kleen for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) { 238225ddbb18SAndi Kleen if ((tmptaint >> i) & 1) 238325ddbb18SAndi Kleen add_taint(i); 238425ddbb18SAndi Kleen } 238525ddbb18SAndi Kleen } 238625ddbb18SAndi Kleen 238725ddbb18SAndi Kleen return err; 238834f5a398STheodore Ts'o } 238934f5a398STheodore Ts'o 23901da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param { 23911da177e4SLinus Torvalds int *min; 23921da177e4SLinus Torvalds int *max; 23931da177e4SLinus Torvalds }; 23941da177e4SLinus Torvalds 239500b7c339SAmerigo Wang static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp, 23961da177e4SLinus Torvalds int *valp, 23971da177e4SLinus Torvalds int write, void *data) 23981da177e4SLinus Torvalds { 23991da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param *param = data; 24001da177e4SLinus Torvalds if (write) { 24011da177e4SLinus Torvalds int val = *negp ? -*lvalp : *lvalp; 24021da177e4SLinus Torvalds if ((param->min && *param->min > val) || 24031da177e4SLinus Torvalds (param->max && *param->max < val)) 24041da177e4SLinus Torvalds return -EINVAL; 24051da177e4SLinus Torvalds *valp = val; 24061da177e4SLinus Torvalds } else { 24071da177e4SLinus Torvalds int val = *valp; 24081da177e4SLinus Torvalds if (val < 0) { 240900b7c339SAmerigo Wang *negp = true; 24101da177e4SLinus Torvalds *lvalp = (unsigned long)-val; 24111da177e4SLinus Torvalds } else { 241200b7c339SAmerigo Wang *negp = false; 24131da177e4SLinus Torvalds *lvalp = (unsigned long)val; 24141da177e4SLinus Torvalds } 24151da177e4SLinus Torvalds } 24161da177e4SLinus Torvalds return 0; 24171da177e4SLinus Torvalds } 24181da177e4SLinus Torvalds 24191da177e4SLinus Torvalds /** 24201da177e4SLinus Torvalds * proc_dointvec_minmax - read a vector of integers with min/max values 24211da177e4SLinus Torvalds * @table: the sysctl table 24221da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 24231da177e4SLinus Torvalds * @buffer: the user buffer 24241da177e4SLinus Torvalds * @lenp: the size of the user buffer 24251da177e4SLinus Torvalds * @ppos: file position 24261da177e4SLinus Torvalds * 24271da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 24281da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 24291da177e4SLinus Torvalds * 24301da177e4SLinus Torvalds * This routine will ensure the values are within the range specified by 24311da177e4SLinus Torvalds * table->extra1 (min) and table->extra2 (max). 24321da177e4SLinus Torvalds * 24331da177e4SLinus Torvalds * Returns 0 on success. 24341da177e4SLinus Torvalds */ 24358d65af78SAlexey Dobriyan int proc_dointvec_minmax(struct ctl_table *table, int write, 24361da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 24371da177e4SLinus Torvalds { 24381da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param param = { 24391da177e4SLinus Torvalds .min = (int *) table->extra1, 24401da177e4SLinus Torvalds .max = (int *) table->extra2, 24411da177e4SLinus Torvalds }; 24428d65af78SAlexey Dobriyan return do_proc_dointvec(table, write, buffer, lenp, ppos, 24431da177e4SLinus Torvalds do_proc_dointvec_minmax_conv, ¶m); 24441da177e4SLinus Torvalds } 24451da177e4SLinus Torvalds 2446d8217f07SEric W. Biederman static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write, 24471da177e4SLinus Torvalds void __user *buffer, 24481da177e4SLinus Torvalds size_t *lenp, loff_t *ppos, 24491da177e4SLinus Torvalds unsigned long convmul, 24501da177e4SLinus Torvalds unsigned long convdiv) 24511da177e4SLinus Torvalds { 245200b7c339SAmerigo Wang unsigned long *i, *min, *max; 245300b7c339SAmerigo Wang int vleft, first = 1, err = 0; 245400b7c339SAmerigo Wang unsigned long page = 0; 245500b7c339SAmerigo Wang size_t left; 245600b7c339SAmerigo Wang char *kbuf; 24571da177e4SLinus Torvalds 245800b7c339SAmerigo Wang if (!data || !table->maxlen || !*lenp || (*ppos && !write)) { 24591da177e4SLinus Torvalds *lenp = 0; 24601da177e4SLinus Torvalds return 0; 24611da177e4SLinus Torvalds } 24621da177e4SLinus Torvalds 2463fcfbd547SKirill Korotaev i = (unsigned long *) data; 24641da177e4SLinus Torvalds min = (unsigned long *) table->extra1; 24651da177e4SLinus Torvalds max = (unsigned long *) table->extra2; 24661da177e4SLinus Torvalds vleft = table->maxlen / sizeof(unsigned long); 24671da177e4SLinus Torvalds left = *lenp; 24681da177e4SLinus Torvalds 24691da177e4SLinus Torvalds if (write) { 247000b7c339SAmerigo Wang if (left > PAGE_SIZE - 1) 247100b7c339SAmerigo Wang left = PAGE_SIZE - 1; 247200b7c339SAmerigo Wang page = __get_free_page(GFP_TEMPORARY); 247300b7c339SAmerigo Wang kbuf = (char *) page; 247400b7c339SAmerigo Wang if (!kbuf) 247500b7c339SAmerigo Wang return -ENOMEM; 247600b7c339SAmerigo Wang if (copy_from_user(kbuf, buffer, left)) { 247700b7c339SAmerigo Wang err = -EFAULT; 247800b7c339SAmerigo Wang goto free; 24791da177e4SLinus Torvalds } 248000b7c339SAmerigo Wang kbuf[left] = 0; 24811da177e4SLinus Torvalds } 24821da177e4SLinus Torvalds 248327b3d80aSEric Dumazet for (; left && vleft--; i++, first = 0) { 248400b7c339SAmerigo Wang unsigned long val; 248500b7c339SAmerigo Wang 248600b7c339SAmerigo Wang if (write) { 248700b7c339SAmerigo Wang bool neg; 248800b7c339SAmerigo Wang 248900b7c339SAmerigo Wang left -= proc_skip_spaces(&kbuf); 249000b7c339SAmerigo Wang 249100b7c339SAmerigo Wang err = proc_get_long(&kbuf, &left, &val, &neg, 249200b7c339SAmerigo Wang proc_wspace_sep, 249300b7c339SAmerigo Wang sizeof(proc_wspace_sep), NULL); 249400b7c339SAmerigo Wang if (err) 249500b7c339SAmerigo Wang break; 24961da177e4SLinus Torvalds if (neg) 24971da177e4SLinus Torvalds continue; 24981da177e4SLinus Torvalds if ((min && val < *min) || (max && val > *max)) 24991da177e4SLinus Torvalds continue; 25001da177e4SLinus Torvalds *i = val; 25011da177e4SLinus Torvalds } else { 250200b7c339SAmerigo Wang val = convdiv * (*i) / convmul; 25031da177e4SLinus Torvalds if (!first) 250400b7c339SAmerigo Wang err = proc_put_char(&buffer, &left, '\t'); 250500b7c339SAmerigo Wang err = proc_put_long(&buffer, &left, val, false); 250600b7c339SAmerigo Wang if (err) 250700b7c339SAmerigo Wang break; 25081da177e4SLinus Torvalds } 25091da177e4SLinus Torvalds } 25101da177e4SLinus Torvalds 251100b7c339SAmerigo Wang if (!write && !first && left && !err) 251200b7c339SAmerigo Wang err = proc_put_char(&buffer, &left, '\n'); 251300b7c339SAmerigo Wang if (write && !err) 251400b7c339SAmerigo Wang left -= proc_skip_spaces(&kbuf); 251500b7c339SAmerigo Wang free: 25161da177e4SLinus Torvalds if (write) { 251700b7c339SAmerigo Wang free_page(page); 251800b7c339SAmerigo Wang if (first) 251900b7c339SAmerigo Wang return err ? : -EINVAL; 25201da177e4SLinus Torvalds } 25211da177e4SLinus Torvalds *lenp -= left; 25221da177e4SLinus Torvalds *ppos += *lenp; 252300b7c339SAmerigo Wang return err; 25241da177e4SLinus Torvalds } 25251da177e4SLinus Torvalds 2526d8217f07SEric W. Biederman static int do_proc_doulongvec_minmax(struct ctl_table *table, int write, 2527fcfbd547SKirill Korotaev void __user *buffer, 2528fcfbd547SKirill Korotaev size_t *lenp, loff_t *ppos, 2529fcfbd547SKirill Korotaev unsigned long convmul, 2530fcfbd547SKirill Korotaev unsigned long convdiv) 2531fcfbd547SKirill Korotaev { 2532fcfbd547SKirill Korotaev return __do_proc_doulongvec_minmax(table->data, table, write, 25338d65af78SAlexey Dobriyan buffer, lenp, ppos, convmul, convdiv); 2534fcfbd547SKirill Korotaev } 2535fcfbd547SKirill Korotaev 25361da177e4SLinus Torvalds /** 25371da177e4SLinus Torvalds * proc_doulongvec_minmax - read a vector of long integers with min/max values 25381da177e4SLinus Torvalds * @table: the sysctl table 25391da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 25401da177e4SLinus Torvalds * @buffer: the user buffer 25411da177e4SLinus Torvalds * @lenp: the size of the user buffer 25421da177e4SLinus Torvalds * @ppos: file position 25431da177e4SLinus Torvalds * 25441da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long 25451da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 25461da177e4SLinus Torvalds * 25471da177e4SLinus Torvalds * This routine will ensure the values are within the range specified by 25481da177e4SLinus Torvalds * table->extra1 (min) and table->extra2 (max). 25491da177e4SLinus Torvalds * 25501da177e4SLinus Torvalds * Returns 0 on success. 25511da177e4SLinus Torvalds */ 25528d65af78SAlexey Dobriyan int proc_doulongvec_minmax(struct ctl_table *table, int write, 25531da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 25541da177e4SLinus Torvalds { 25558d65af78SAlexey Dobriyan return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l); 25561da177e4SLinus Torvalds } 25571da177e4SLinus Torvalds 25581da177e4SLinus Torvalds /** 25591da177e4SLinus Torvalds * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values 25601da177e4SLinus Torvalds * @table: the sysctl table 25611da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 25621da177e4SLinus Torvalds * @buffer: the user buffer 25631da177e4SLinus Torvalds * @lenp: the size of the user buffer 25641da177e4SLinus Torvalds * @ppos: file position 25651da177e4SLinus Torvalds * 25661da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long 25671da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. The values 25681da177e4SLinus Torvalds * are treated as milliseconds, and converted to jiffies when they are stored. 25691da177e4SLinus Torvalds * 25701da177e4SLinus Torvalds * This routine will ensure the values are within the range specified by 25711da177e4SLinus Torvalds * table->extra1 (min) and table->extra2 (max). 25721da177e4SLinus Torvalds * 25731da177e4SLinus Torvalds * Returns 0 on success. 25741da177e4SLinus Torvalds */ 2575d8217f07SEric W. Biederman int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, 25761da177e4SLinus Torvalds void __user *buffer, 25771da177e4SLinus Torvalds size_t *lenp, loff_t *ppos) 25781da177e4SLinus Torvalds { 25798d65af78SAlexey Dobriyan return do_proc_doulongvec_minmax(table, write, buffer, 25801da177e4SLinus Torvalds lenp, ppos, HZ, 1000l); 25811da177e4SLinus Torvalds } 25821da177e4SLinus Torvalds 25831da177e4SLinus Torvalds 258400b7c339SAmerigo Wang static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp, 25851da177e4SLinus Torvalds int *valp, 25861da177e4SLinus Torvalds int write, void *data) 25871da177e4SLinus Torvalds { 25881da177e4SLinus Torvalds if (write) { 2589cba9f33dSBart Samwel if (*lvalp > LONG_MAX / HZ) 2590cba9f33dSBart Samwel return 1; 25911da177e4SLinus Torvalds *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ); 25921da177e4SLinus Torvalds } else { 25931da177e4SLinus Torvalds int val = *valp; 25941da177e4SLinus Torvalds unsigned long lval; 25951da177e4SLinus Torvalds if (val < 0) { 259600b7c339SAmerigo Wang *negp = true; 25971da177e4SLinus Torvalds lval = (unsigned long)-val; 25981da177e4SLinus Torvalds } else { 259900b7c339SAmerigo Wang *negp = false; 26001da177e4SLinus Torvalds lval = (unsigned long)val; 26011da177e4SLinus Torvalds } 26021da177e4SLinus Torvalds *lvalp = lval / HZ; 26031da177e4SLinus Torvalds } 26041da177e4SLinus Torvalds return 0; 26051da177e4SLinus Torvalds } 26061da177e4SLinus Torvalds 260700b7c339SAmerigo Wang static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp, 26081da177e4SLinus Torvalds int *valp, 26091da177e4SLinus Torvalds int write, void *data) 26101da177e4SLinus Torvalds { 26111da177e4SLinus Torvalds if (write) { 2612cba9f33dSBart Samwel if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ) 2613cba9f33dSBart Samwel return 1; 26141da177e4SLinus Torvalds *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp); 26151da177e4SLinus Torvalds } else { 26161da177e4SLinus Torvalds int val = *valp; 26171da177e4SLinus Torvalds unsigned long lval; 26181da177e4SLinus Torvalds if (val < 0) { 261900b7c339SAmerigo Wang *negp = true; 26201da177e4SLinus Torvalds lval = (unsigned long)-val; 26211da177e4SLinus Torvalds } else { 262200b7c339SAmerigo Wang *negp = false; 26231da177e4SLinus Torvalds lval = (unsigned long)val; 26241da177e4SLinus Torvalds } 26251da177e4SLinus Torvalds *lvalp = jiffies_to_clock_t(lval); 26261da177e4SLinus Torvalds } 26271da177e4SLinus Torvalds return 0; 26281da177e4SLinus Torvalds } 26291da177e4SLinus Torvalds 263000b7c339SAmerigo Wang static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp, 26311da177e4SLinus Torvalds int *valp, 26321da177e4SLinus Torvalds int write, void *data) 26331da177e4SLinus Torvalds { 26341da177e4SLinus Torvalds if (write) { 26351da177e4SLinus Torvalds *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp); 26361da177e4SLinus Torvalds } else { 26371da177e4SLinus Torvalds int val = *valp; 26381da177e4SLinus Torvalds unsigned long lval; 26391da177e4SLinus Torvalds if (val < 0) { 264000b7c339SAmerigo Wang *negp = true; 26411da177e4SLinus Torvalds lval = (unsigned long)-val; 26421da177e4SLinus Torvalds } else { 264300b7c339SAmerigo Wang *negp = false; 26441da177e4SLinus Torvalds lval = (unsigned long)val; 26451da177e4SLinus Torvalds } 26461da177e4SLinus Torvalds *lvalp = jiffies_to_msecs(lval); 26471da177e4SLinus Torvalds } 26481da177e4SLinus Torvalds return 0; 26491da177e4SLinus Torvalds } 26501da177e4SLinus Torvalds 26511da177e4SLinus Torvalds /** 26521da177e4SLinus Torvalds * proc_dointvec_jiffies - read a vector of integers as seconds 26531da177e4SLinus Torvalds * @table: the sysctl table 26541da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 26551da177e4SLinus Torvalds * @buffer: the user buffer 26561da177e4SLinus Torvalds * @lenp: the size of the user buffer 26571da177e4SLinus Torvalds * @ppos: file position 26581da177e4SLinus Torvalds * 26591da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 26601da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 26611da177e4SLinus Torvalds * The values read are assumed to be in seconds, and are converted into 26621da177e4SLinus Torvalds * jiffies. 26631da177e4SLinus Torvalds * 26641da177e4SLinus Torvalds * Returns 0 on success. 26651da177e4SLinus Torvalds */ 26668d65af78SAlexey Dobriyan int proc_dointvec_jiffies(struct ctl_table *table, int write, 26671da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 26681da177e4SLinus Torvalds { 26698d65af78SAlexey Dobriyan return do_proc_dointvec(table,write,buffer,lenp,ppos, 26701da177e4SLinus Torvalds do_proc_dointvec_jiffies_conv,NULL); 26711da177e4SLinus Torvalds } 26721da177e4SLinus Torvalds 26731da177e4SLinus Torvalds /** 26741da177e4SLinus Torvalds * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds 26751da177e4SLinus Torvalds * @table: the sysctl table 26761da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 26771da177e4SLinus Torvalds * @buffer: the user buffer 26781da177e4SLinus Torvalds * @lenp: the size of the user buffer 26791e5d5331SRandy Dunlap * @ppos: pointer to the file position 26801da177e4SLinus Torvalds * 26811da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 26821da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 26831da177e4SLinus Torvalds * The values read are assumed to be in 1/USER_HZ seconds, and 26841da177e4SLinus Torvalds * are converted into jiffies. 26851da177e4SLinus Torvalds * 26861da177e4SLinus Torvalds * Returns 0 on success. 26871da177e4SLinus Torvalds */ 26888d65af78SAlexey Dobriyan int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, 26891da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 26901da177e4SLinus Torvalds { 26918d65af78SAlexey Dobriyan return do_proc_dointvec(table,write,buffer,lenp,ppos, 26921da177e4SLinus Torvalds do_proc_dointvec_userhz_jiffies_conv,NULL); 26931da177e4SLinus Torvalds } 26941da177e4SLinus Torvalds 26951da177e4SLinus Torvalds /** 26961da177e4SLinus Torvalds * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds 26971da177e4SLinus Torvalds * @table: the sysctl table 26981da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 26991da177e4SLinus Torvalds * @buffer: the user buffer 27001da177e4SLinus Torvalds * @lenp: the size of the user buffer 270167be2dd1SMartin Waitz * @ppos: file position 270267be2dd1SMartin Waitz * @ppos: the current position in the file 27031da177e4SLinus Torvalds * 27041da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 27051da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 27061da177e4SLinus Torvalds * The values read are assumed to be in 1/1000 seconds, and 27071da177e4SLinus Torvalds * are converted into jiffies. 27081da177e4SLinus Torvalds * 27091da177e4SLinus Torvalds * Returns 0 on success. 27101da177e4SLinus Torvalds */ 27118d65af78SAlexey Dobriyan int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, 27121da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 27131da177e4SLinus Torvalds { 27148d65af78SAlexey Dobriyan return do_proc_dointvec(table, write, buffer, lenp, ppos, 27151da177e4SLinus Torvalds do_proc_dointvec_ms_jiffies_conv, NULL); 27161da177e4SLinus Torvalds } 27171da177e4SLinus Torvalds 27188d65af78SAlexey Dobriyan static int proc_do_cad_pid(struct ctl_table *table, int write, 27199ec52099SCedric Le Goater void __user *buffer, size_t *lenp, loff_t *ppos) 27209ec52099SCedric Le Goater { 27219ec52099SCedric Le Goater struct pid *new_pid; 27229ec52099SCedric Le Goater pid_t tmp; 27239ec52099SCedric Le Goater int r; 27249ec52099SCedric Le Goater 27256c5f3e7bSPavel Emelyanov tmp = pid_vnr(cad_pid); 27269ec52099SCedric Le Goater 27278d65af78SAlexey Dobriyan r = __do_proc_dointvec(&tmp, table, write, buffer, 27289ec52099SCedric Le Goater lenp, ppos, NULL, NULL); 27299ec52099SCedric Le Goater if (r || !write) 27309ec52099SCedric Le Goater return r; 27319ec52099SCedric Le Goater 27329ec52099SCedric Le Goater new_pid = find_get_pid(tmp); 27339ec52099SCedric Le Goater if (!new_pid) 27349ec52099SCedric Le Goater return -ESRCH; 27359ec52099SCedric Le Goater 27369ec52099SCedric Le Goater put_pid(xchg(&cad_pid, new_pid)); 27379ec52099SCedric Le Goater return 0; 27389ec52099SCedric Le Goater } 27399ec52099SCedric Le Goater 27409f977fb7SOctavian Purdila /** 27419f977fb7SOctavian Purdila * proc_do_large_bitmap - read/write from/to a large bitmap 27429f977fb7SOctavian Purdila * @table: the sysctl table 27439f977fb7SOctavian Purdila * @write: %TRUE if this is a write to the sysctl file 27449f977fb7SOctavian Purdila * @buffer: the user buffer 27459f977fb7SOctavian Purdila * @lenp: the size of the user buffer 27469f977fb7SOctavian Purdila * @ppos: file position 27479f977fb7SOctavian Purdila * 27489f977fb7SOctavian Purdila * The bitmap is stored at table->data and the bitmap length (in bits) 27499f977fb7SOctavian Purdila * in table->maxlen. 27509f977fb7SOctavian Purdila * 27519f977fb7SOctavian Purdila * We use a range comma separated format (e.g. 1,3-4,10-10) so that 27529f977fb7SOctavian Purdila * large bitmaps may be represented in a compact manner. Writing into 27539f977fb7SOctavian Purdila * the file will clear the bitmap then update it with the given input. 27549f977fb7SOctavian Purdila * 27559f977fb7SOctavian Purdila * Returns 0 on success. 27569f977fb7SOctavian Purdila */ 27579f977fb7SOctavian Purdila int proc_do_large_bitmap(struct ctl_table *table, int write, 27589f977fb7SOctavian Purdila void __user *buffer, size_t *lenp, loff_t *ppos) 27599f977fb7SOctavian Purdila { 27609f977fb7SOctavian Purdila int err = 0; 27619f977fb7SOctavian Purdila bool first = 1; 27629f977fb7SOctavian Purdila size_t left = *lenp; 27639f977fb7SOctavian Purdila unsigned long bitmap_len = table->maxlen; 27649f977fb7SOctavian Purdila unsigned long *bitmap = (unsigned long *) table->data; 27659f977fb7SOctavian Purdila unsigned long *tmp_bitmap = NULL; 27669f977fb7SOctavian Purdila char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c; 27679f977fb7SOctavian Purdila 27689f977fb7SOctavian Purdila if (!bitmap_len || !left || (*ppos && !write)) { 27699f977fb7SOctavian Purdila *lenp = 0; 27709f977fb7SOctavian Purdila return 0; 27719f977fb7SOctavian Purdila } 27729f977fb7SOctavian Purdila 27739f977fb7SOctavian Purdila if (write) { 27749f977fb7SOctavian Purdila unsigned long page = 0; 27759f977fb7SOctavian Purdila char *kbuf; 27769f977fb7SOctavian Purdila 27779f977fb7SOctavian Purdila if (left > PAGE_SIZE - 1) 27789f977fb7SOctavian Purdila left = PAGE_SIZE - 1; 27799f977fb7SOctavian Purdila 27809f977fb7SOctavian Purdila page = __get_free_page(GFP_TEMPORARY); 27819f977fb7SOctavian Purdila kbuf = (char *) page; 27829f977fb7SOctavian Purdila if (!kbuf) 27839f977fb7SOctavian Purdila return -ENOMEM; 27849f977fb7SOctavian Purdila if (copy_from_user(kbuf, buffer, left)) { 27859f977fb7SOctavian Purdila free_page(page); 27869f977fb7SOctavian Purdila return -EFAULT; 27879f977fb7SOctavian Purdila } 27889f977fb7SOctavian Purdila kbuf[left] = 0; 27899f977fb7SOctavian Purdila 27909f977fb7SOctavian Purdila tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long), 27919f977fb7SOctavian Purdila GFP_KERNEL); 27929f977fb7SOctavian Purdila if (!tmp_bitmap) { 27939f977fb7SOctavian Purdila free_page(page); 27949f977fb7SOctavian Purdila return -ENOMEM; 27959f977fb7SOctavian Purdila } 27969f977fb7SOctavian Purdila proc_skip_char(&kbuf, &left, '\n'); 27979f977fb7SOctavian Purdila while (!err && left) { 27989f977fb7SOctavian Purdila unsigned long val_a, val_b; 27999f977fb7SOctavian Purdila bool neg; 28009f977fb7SOctavian Purdila 28019f977fb7SOctavian Purdila err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a, 28029f977fb7SOctavian Purdila sizeof(tr_a), &c); 28039f977fb7SOctavian Purdila if (err) 28049f977fb7SOctavian Purdila break; 28059f977fb7SOctavian Purdila if (val_a >= bitmap_len || neg) { 28069f977fb7SOctavian Purdila err = -EINVAL; 28079f977fb7SOctavian Purdila break; 28089f977fb7SOctavian Purdila } 28099f977fb7SOctavian Purdila 28109f977fb7SOctavian Purdila val_b = val_a; 28119f977fb7SOctavian Purdila if (left) { 28129f977fb7SOctavian Purdila kbuf++; 28139f977fb7SOctavian Purdila left--; 28149f977fb7SOctavian Purdila } 28159f977fb7SOctavian Purdila 28169f977fb7SOctavian Purdila if (c == '-') { 28179f977fb7SOctavian Purdila err = proc_get_long(&kbuf, &left, &val_b, 28189f977fb7SOctavian Purdila &neg, tr_b, sizeof(tr_b), 28199f977fb7SOctavian Purdila &c); 28209f977fb7SOctavian Purdila if (err) 28219f977fb7SOctavian Purdila break; 28229f977fb7SOctavian Purdila if (val_b >= bitmap_len || neg || 28239f977fb7SOctavian Purdila val_a > val_b) { 28249f977fb7SOctavian Purdila err = -EINVAL; 28259f977fb7SOctavian Purdila break; 28269f977fb7SOctavian Purdila } 28279f977fb7SOctavian Purdila if (left) { 28289f977fb7SOctavian Purdila kbuf++; 28299f977fb7SOctavian Purdila left--; 28309f977fb7SOctavian Purdila } 28319f977fb7SOctavian Purdila } 28329f977fb7SOctavian Purdila 28339f977fb7SOctavian Purdila while (val_a <= val_b) 28349f977fb7SOctavian Purdila set_bit(val_a++, tmp_bitmap); 28359f977fb7SOctavian Purdila 28369f977fb7SOctavian Purdila first = 0; 28379f977fb7SOctavian Purdila proc_skip_char(&kbuf, &left, '\n'); 28389f977fb7SOctavian Purdila } 28399f977fb7SOctavian Purdila free_page(page); 28409f977fb7SOctavian Purdila } else { 28419f977fb7SOctavian Purdila unsigned long bit_a, bit_b = 0; 28429f977fb7SOctavian Purdila 28439f977fb7SOctavian Purdila while (left) { 28449f977fb7SOctavian Purdila bit_a = find_next_bit(bitmap, bitmap_len, bit_b); 28459f977fb7SOctavian Purdila if (bit_a >= bitmap_len) 28469f977fb7SOctavian Purdila break; 28479f977fb7SOctavian Purdila bit_b = find_next_zero_bit(bitmap, bitmap_len, 28489f977fb7SOctavian Purdila bit_a + 1) - 1; 28499f977fb7SOctavian Purdila 28509f977fb7SOctavian Purdila if (!first) { 28519f977fb7SOctavian Purdila err = proc_put_char(&buffer, &left, ','); 28529f977fb7SOctavian Purdila if (err) 28539f977fb7SOctavian Purdila break; 28549f977fb7SOctavian Purdila } 28559f977fb7SOctavian Purdila err = proc_put_long(&buffer, &left, bit_a, false); 28569f977fb7SOctavian Purdila if (err) 28579f977fb7SOctavian Purdila break; 28589f977fb7SOctavian Purdila if (bit_a != bit_b) { 28599f977fb7SOctavian Purdila err = proc_put_char(&buffer, &left, '-'); 28609f977fb7SOctavian Purdila if (err) 28619f977fb7SOctavian Purdila break; 28629f977fb7SOctavian Purdila err = proc_put_long(&buffer, &left, bit_b, false); 28639f977fb7SOctavian Purdila if (err) 28649f977fb7SOctavian Purdila break; 28659f977fb7SOctavian Purdila } 28669f977fb7SOctavian Purdila 28679f977fb7SOctavian Purdila first = 0; bit_b++; 28689f977fb7SOctavian Purdila } 28699f977fb7SOctavian Purdila if (!err) 28709f977fb7SOctavian Purdila err = proc_put_char(&buffer, &left, '\n'); 28719f977fb7SOctavian Purdila } 28729f977fb7SOctavian Purdila 28739f977fb7SOctavian Purdila if (!err) { 28749f977fb7SOctavian Purdila if (write) { 28759f977fb7SOctavian Purdila if (*ppos) 28769f977fb7SOctavian Purdila bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len); 28779f977fb7SOctavian Purdila else 28789f977fb7SOctavian Purdila memcpy(bitmap, tmp_bitmap, 28799f977fb7SOctavian Purdila BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long)); 28809f977fb7SOctavian Purdila } 28819f977fb7SOctavian Purdila kfree(tmp_bitmap); 28829f977fb7SOctavian Purdila *lenp -= left; 28839f977fb7SOctavian Purdila *ppos += *lenp; 28849f977fb7SOctavian Purdila return 0; 28859f977fb7SOctavian Purdila } else { 28869f977fb7SOctavian Purdila kfree(tmp_bitmap); 28879f977fb7SOctavian Purdila return err; 28889f977fb7SOctavian Purdila } 28899f977fb7SOctavian Purdila } 28909f977fb7SOctavian Purdila 28911da177e4SLinus Torvalds #else /* CONFIG_PROC_FS */ 28921da177e4SLinus Torvalds 28938d65af78SAlexey Dobriyan int proc_dostring(struct ctl_table *table, int write, 28941da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 28951da177e4SLinus Torvalds { 28961da177e4SLinus Torvalds return -ENOSYS; 28971da177e4SLinus Torvalds } 28981da177e4SLinus Torvalds 28998d65af78SAlexey Dobriyan int proc_dointvec(struct ctl_table *table, int write, 29001da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 29011da177e4SLinus Torvalds { 29021da177e4SLinus Torvalds return -ENOSYS; 29031da177e4SLinus Torvalds } 29041da177e4SLinus Torvalds 29058d65af78SAlexey Dobriyan int proc_dointvec_minmax(struct ctl_table *table, int write, 29061da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 29071da177e4SLinus Torvalds { 29081da177e4SLinus Torvalds return -ENOSYS; 29091da177e4SLinus Torvalds } 29101da177e4SLinus Torvalds 29118d65af78SAlexey Dobriyan int proc_dointvec_jiffies(struct ctl_table *table, int write, 29121da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 29131da177e4SLinus Torvalds { 29141da177e4SLinus Torvalds return -ENOSYS; 29151da177e4SLinus Torvalds } 29161da177e4SLinus Torvalds 29178d65af78SAlexey Dobriyan int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, 29181da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 29191da177e4SLinus Torvalds { 29201da177e4SLinus Torvalds return -ENOSYS; 29211da177e4SLinus Torvalds } 29221da177e4SLinus Torvalds 29238d65af78SAlexey Dobriyan int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, 29241da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 29251da177e4SLinus Torvalds { 29261da177e4SLinus Torvalds return -ENOSYS; 29271da177e4SLinus Torvalds } 29281da177e4SLinus Torvalds 29298d65af78SAlexey Dobriyan int proc_doulongvec_minmax(struct ctl_table *table, int write, 29301da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 29311da177e4SLinus Torvalds { 29321da177e4SLinus Torvalds return -ENOSYS; 29331da177e4SLinus Torvalds } 29341da177e4SLinus Torvalds 2935d8217f07SEric W. Biederman int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, 29361da177e4SLinus Torvalds void __user *buffer, 29371da177e4SLinus Torvalds size_t *lenp, loff_t *ppos) 29381da177e4SLinus Torvalds { 29391da177e4SLinus Torvalds return -ENOSYS; 29401da177e4SLinus Torvalds } 29411da177e4SLinus Torvalds 29421da177e4SLinus Torvalds 29431da177e4SLinus Torvalds #endif /* CONFIG_PROC_FS */ 29441da177e4SLinus Torvalds 29451da177e4SLinus Torvalds /* 29461da177e4SLinus Torvalds * No sense putting this after each symbol definition, twice, 29471da177e4SLinus Torvalds * exception granted :-) 29481da177e4SLinus Torvalds */ 29491da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec); 29501da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies); 29511da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax); 29521da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies); 29531da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies); 29541da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring); 29551da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax); 29561da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); 29571da177e4SLinus Torvalds EXPORT_SYMBOL(register_sysctl_table); 295829e796fdSEric W. Biederman EXPORT_SYMBOL(register_sysctl_paths); 29591da177e4SLinus Torvalds EXPORT_SYMBOL(unregister_sysctl_table); 2960