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> 27455cd5abSDan Rosenberg #include <linux/printk.h> 281da177e4SLinus Torvalds #include <linux/proc_fs.h> 2972c2d582SAndrew Morgan #include <linux/security.h> 301da177e4SLinus Torvalds #include <linux/ctype.h> 31dfec072eSVegard Nossum #include <linux/kmemcheck.h> 3262239ac2SAdrian Bunk #include <linux/fs.h> 331da177e4SLinus Torvalds #include <linux/init.h> 341da177e4SLinus Torvalds #include <linux/kernel.h> 350296b228SKay Sievers #include <linux/kobject.h> 3620380731SArnaldo Carvalho de Melo #include <linux/net.h> 371da177e4SLinus Torvalds #include <linux/sysrq.h> 381da177e4SLinus Torvalds #include <linux/highuid.h> 391da177e4SLinus Torvalds #include <linux/writeback.h> 403fff4c42SIngo Molnar #include <linux/ratelimit.h> 4176ab0f53SMel Gorman #include <linux/compaction.h> 421da177e4SLinus Torvalds #include <linux/hugetlb.h> 431da177e4SLinus Torvalds #include <linux/initrd.h> 440b77f5bfSDavid Howells #include <linux/key.h> 451da177e4SLinus Torvalds #include <linux/times.h> 461da177e4SLinus Torvalds #include <linux/limits.h> 471da177e4SLinus Torvalds #include <linux/dcache.h> 486e006701SAlexey Dobriyan #include <linux/dnotify.h> 491da177e4SLinus Torvalds #include <linux/syscalls.h> 50c748e134SAdrian Bunk #include <linux/vmstat.h> 51c255d844SPavel Machek #include <linux/nfs_fs.h> 52c255d844SPavel Machek #include <linux/acpi.h> 5310a0a8d4SJeremy Fitzhardinge #include <linux/reboot.h> 54b0fc494fSSteven Rostedt #include <linux/ftrace.h> 55cdd6c482SIngo Molnar #include <linux/perf_event.h> 56b2be84dfSMasami Hiramatsu #include <linux/kprobes.h> 57b492e95bSJens Axboe #include <linux/pipe_fs_i.h> 588e4228e1SDavid Rientjes #include <linux/oom.h> 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds #include <asm/uaccess.h> 611da177e4SLinus Torvalds #include <asm/processor.h> 621da177e4SLinus Torvalds 6329cbc78bSAndi Kleen #ifdef CONFIG_X86 6429cbc78bSAndi Kleen #include <asm/nmi.h> 650741f4d2SChuck Ebbert #include <asm/stacktrace.h> 666e7c4025SIngo Molnar #include <asm/io.h> 6729cbc78bSAndi Kleen #endif 68c55b7c3eSDave Young #ifdef CONFIG_BSD_PROCESS_ACCT 69c55b7c3eSDave Young #include <linux/acct.h> 70c55b7c3eSDave Young #endif 714f0e056fSDave Young #ifdef CONFIG_RT_MUTEXES 724f0e056fSDave Young #include <linux/rtmutex.h> 734f0e056fSDave Young #endif 742edf5e49SDave Young #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT) 752edf5e49SDave Young #include <linux/lockdep.h> 762edf5e49SDave Young #endif 7715485a46SDave Young #ifdef CONFIG_CHR_DEV_SG 7815485a46SDave Young #include <scsi/sg.h> 7915485a46SDave Young #endif 8029cbc78bSAndi Kleen 8158687acbSDon Zickus #ifdef CONFIG_LOCKUP_DETECTOR 82504d7cf1SDon Zickus #include <linux/nmi.h> 83504d7cf1SDon Zickus #endif 84504d7cf1SDon Zickus 857058cb02SEric W. Biederman 861da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL) 871da177e4SLinus Torvalds 881da177e4SLinus Torvalds /* External variables not in a header file. */ 891da177e4SLinus Torvalds extern int sysctl_overcommit_memory; 901da177e4SLinus Torvalds extern int sysctl_overcommit_ratio; 911da177e4SLinus Torvalds extern int max_threads; 921da177e4SLinus Torvalds extern int core_uses_pid; 93d6e71144SAlan Cox extern int suid_dumpable; 941da177e4SLinus Torvalds extern char core_pattern[]; 95a293980cSNeil Horman extern unsigned int core_pipe_limit; 961da177e4SLinus Torvalds extern int pid_max; 971da177e4SLinus Torvalds extern int min_free_kbytes; 981da177e4SLinus Torvalds extern int pid_max_min, pid_max_max; 999d0243bcSAndrew Morton extern int sysctl_drop_caches; 1008ad4b1fbSRohit Seth extern int percpu_pagelist_fraction; 101bebfa101SAndi Kleen extern int compat_log; 1029745512cSArjan van de Ven extern int latencytop_enabled; 103eceea0b3SAl Viro extern int sysctl_nr_open_min, sysctl_nr_open_max; 104dd8632a1SPaul Mundt #ifndef CONFIG_MMU 105dd8632a1SPaul Mundt extern int sysctl_nr_trim_pages; 106dd8632a1SPaul Mundt #endif 107cb684b5bSJens Axboe #ifdef CONFIG_BLOCK 1085e605b64SJens Axboe extern int blk_iopoll_enabled; 109cb684b5bSJens Axboe #endif 1101da177e4SLinus Torvalds 111c4f3b63fSRavikiran G Thirumalai /* Constants used for minimum and maximum */ 1122508ce18SDon Zickus #ifdef CONFIG_LOCKUP_DETECTOR 113c4f3b63fSRavikiran G Thirumalai static int sixty = 60; 1149383d967SDimitri Sivanich static int neg_one = -1; 115c4f3b63fSRavikiran G Thirumalai #endif 116c4f3b63fSRavikiran G Thirumalai 117c4f3b63fSRavikiran G Thirumalai static int zero; 118cd5f9a4cSLinus Torvalds static int __maybe_unused one = 1; 119cd5f9a4cSLinus Torvalds static int __maybe_unused two = 2; 120cb16e95fSPetr Holasek static int __maybe_unused three = 3; 121fc3501d4SSven Wegener static unsigned long one_ul = 1; 122c4f3b63fSRavikiran G Thirumalai static int one_hundred = 100; 123af91322eSDave Young #ifdef CONFIG_PRINTK 124af91322eSDave Young static int ten_thousand = 10000; 125af91322eSDave Young #endif 126c4f3b63fSRavikiran G Thirumalai 1279e4a5bdaSAndrea Righi /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */ 1289e4a5bdaSAndrea Righi static unsigned long dirty_bytes_min = 2 * PAGE_SIZE; 1299e4a5bdaSAndrea Righi 1301da177e4SLinus Torvalds /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */ 1311da177e4SLinus Torvalds static int maxolduid = 65535; 1321da177e4SLinus Torvalds static int minolduid; 1338ad4b1fbSRohit Seth static int min_percpu_pagelist_fract = 8; 1341da177e4SLinus Torvalds 1351da177e4SLinus Torvalds static int ngroups_max = NGROUPS_MAX; 1361da177e4SLinus Torvalds 137d14f1729SDave Young #ifdef CONFIG_INOTIFY_USER 138d14f1729SDave Young #include <linux/inotify.h> 139d14f1729SDave Young #endif 14072c57ed5SDavid S. Miller #ifdef CONFIG_SPARC 14117f04fbbSDavid S. Miller #include <asm/system.h> 1421da177e4SLinus Torvalds #endif 1431da177e4SLinus Torvalds 1440871420fSDavid S. Miller #ifdef CONFIG_SPARC64 1450871420fSDavid S. Miller extern int sysctl_tsb_ratio; 1460871420fSDavid S. Miller #endif 1470871420fSDavid S. Miller 1481da177e4SLinus Torvalds #ifdef __hppa__ 1491da177e4SLinus Torvalds extern int pwrsw_enabled; 1501da177e4SLinus Torvalds extern int unaligned_enabled; 1511da177e4SLinus Torvalds #endif 1521da177e4SLinus Torvalds 153347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390 1541da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU 1551da177e4SLinus Torvalds extern int sysctl_ieee_emulation_warnings; 1561da177e4SLinus Torvalds #endif 1571da177e4SLinus Torvalds extern int sysctl_userprocess_debug; 158951f22d5SMartin Schwidefsky extern int spin_retry; 1591da177e4SLinus Torvalds #endif 1601da177e4SLinus Torvalds 161d2b176edSJes Sorensen #ifdef CONFIG_IA64 162d2b176edSJes Sorensen extern int no_unaligned_warning; 16388fc241fSDoug Chapman extern int unaligned_dump_stack; 164d2b176edSJes Sorensen #endif 165d2b176edSJes Sorensen 166d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL 1678d65af78SAlexey Dobriyan static int proc_do_cad_pid(struct ctl_table *table, int write, 1689ec52099SCedric Le Goater void __user *buffer, size_t *lenp, loff_t *ppos); 1698d65af78SAlexey Dobriyan static int proc_taint(struct ctl_table *table, int write, 17034f5a398STheodore Ts'o void __user *buffer, size_t *lenp, loff_t *ppos); 171d6f8ff73SRandy Dunlap #endif 1729ec52099SCedric Le Goater 173*bfdc0b49SRichard Weinberger #ifdef CONFIG_PRINTK 174*bfdc0b49SRichard Weinberger static int proc_dmesg_restrict(struct ctl_table *table, int write, 175*bfdc0b49SRichard Weinberger void __user *buffer, size_t *lenp, loff_t *ppos); 176*bfdc0b49SRichard Weinberger #endif 177*bfdc0b49SRichard Weinberger 17897f5f0cdSDmitry Torokhov #ifdef CONFIG_MAGIC_SYSRQ 1798c6a98b2SAndy Whitcroft /* Note: sysrq code uses it's own private copy */ 1808c6a98b2SAndy Whitcroft static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE; 18197f5f0cdSDmitry Torokhov 18297f5f0cdSDmitry Torokhov static int sysrq_sysctl_handler(ctl_table *table, int write, 18397f5f0cdSDmitry Torokhov void __user *buffer, size_t *lenp, 18497f5f0cdSDmitry Torokhov loff_t *ppos) 18597f5f0cdSDmitry Torokhov { 18697f5f0cdSDmitry Torokhov int error; 18797f5f0cdSDmitry Torokhov 18897f5f0cdSDmitry Torokhov error = proc_dointvec(table, write, buffer, lenp, ppos); 18997f5f0cdSDmitry Torokhov if (error) 19097f5f0cdSDmitry Torokhov return error; 19197f5f0cdSDmitry Torokhov 19297f5f0cdSDmitry Torokhov if (write) 19397f5f0cdSDmitry Torokhov sysrq_toggle_support(__sysrq_enabled); 19497f5f0cdSDmitry Torokhov 19597f5f0cdSDmitry Torokhov return 0; 19697f5f0cdSDmitry Torokhov } 19797f5f0cdSDmitry Torokhov 19897f5f0cdSDmitry Torokhov #endif 19997f5f0cdSDmitry Torokhov 200d8217f07SEric W. Biederman static struct ctl_table root_table[]; 201e51b6ba0SEric W. Biederman static struct ctl_table_root sysctl_table_root; 202e51b6ba0SEric W. Biederman static struct ctl_table_header root_table_header = { 203dfef6dcdSAl Viro {{.count = 1, 204e51b6ba0SEric W. Biederman .ctl_table = root_table, 205dfef6dcdSAl Viro .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),}}, 206e51b6ba0SEric W. Biederman .root = &sysctl_table_root, 20773455092SAl Viro .set = &sysctl_table_root.default_set, 208e51b6ba0SEric W. Biederman }; 209e51b6ba0SEric W. Biederman static struct ctl_table_root sysctl_table_root = { 210e51b6ba0SEric W. Biederman .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list), 21173455092SAl Viro .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry), 212e51b6ba0SEric W. Biederman }; 2131da177e4SLinus Torvalds 214d8217f07SEric W. Biederman static struct ctl_table kern_table[]; 215d8217f07SEric W. Biederman static struct ctl_table vm_table[]; 216d8217f07SEric W. Biederman static struct ctl_table fs_table[]; 217d8217f07SEric W. Biederman static struct ctl_table debug_table[]; 218d8217f07SEric W. Biederman static struct ctl_table dev_table[]; 219d8217f07SEric W. Biederman extern struct ctl_table random_table[]; 2207ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL 2217ef9964eSDavide Libenzi extern struct ctl_table epoll_table[]; 2227ef9964eSDavide Libenzi #endif 2231da177e4SLinus Torvalds 2241da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT 2251da177e4SLinus Torvalds int sysctl_legacy_va_layout; 2261da177e4SLinus Torvalds #endif 2271da177e4SLinus Torvalds 2281da177e4SLinus Torvalds /* The default sysctl tables: */ 2291da177e4SLinus Torvalds 230d8217f07SEric W. Biederman static struct ctl_table root_table[] = { 2311da177e4SLinus Torvalds { 2321da177e4SLinus Torvalds .procname = "kernel", 2331da177e4SLinus Torvalds .mode = 0555, 2341da177e4SLinus Torvalds .child = kern_table, 2351da177e4SLinus Torvalds }, 2361da177e4SLinus Torvalds { 2371da177e4SLinus Torvalds .procname = "vm", 2381da177e4SLinus Torvalds .mode = 0555, 2391da177e4SLinus Torvalds .child = vm_table, 2401da177e4SLinus Torvalds }, 2411da177e4SLinus Torvalds { 2421da177e4SLinus Torvalds .procname = "fs", 2431da177e4SLinus Torvalds .mode = 0555, 2441da177e4SLinus Torvalds .child = fs_table, 2451da177e4SLinus Torvalds }, 2461da177e4SLinus Torvalds { 2471da177e4SLinus Torvalds .procname = "debug", 2481da177e4SLinus Torvalds .mode = 0555, 2491da177e4SLinus Torvalds .child = debug_table, 2501da177e4SLinus Torvalds }, 2511da177e4SLinus Torvalds { 2521da177e4SLinus Torvalds .procname = "dev", 2531da177e4SLinus Torvalds .mode = 0555, 2541da177e4SLinus Torvalds .child = dev_table, 2551da177e4SLinus Torvalds }, 2566fce56ecSEric W. Biederman { } 2571da177e4SLinus Torvalds }; 2581da177e4SLinus Torvalds 25977e54a1fSIngo Molnar #ifdef CONFIG_SCHED_DEBUG 26073c4efd2SEric Dumazet static int min_sched_granularity_ns = 100000; /* 100 usecs */ 26173c4efd2SEric Dumazet static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */ 26273c4efd2SEric Dumazet static int min_wakeup_granularity_ns; /* 0 usecs */ 26373c4efd2SEric Dumazet static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */ 2641983a922SChristian Ehrhardt static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE; 2651983a922SChristian Ehrhardt static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1; 26677e54a1fSIngo Molnar #endif 26777e54a1fSIngo Molnar 2685e771905SMel Gorman #ifdef CONFIG_COMPACTION 2695e771905SMel Gorman static int min_extfrag_threshold; 2705e771905SMel Gorman static int max_extfrag_threshold = 1000; 2715e771905SMel Gorman #endif 2725e771905SMel Gorman 273d8217f07SEric W. Biederman static struct ctl_table kern_table[] = { 2742bba22c5SMike Galbraith { 2752bba22c5SMike Galbraith .procname = "sched_child_runs_first", 2762bba22c5SMike Galbraith .data = &sysctl_sched_child_runs_first, 2772bba22c5SMike Galbraith .maxlen = sizeof(unsigned int), 2782bba22c5SMike Galbraith .mode = 0644, 2796d456111SEric W. Biederman .proc_handler = proc_dointvec, 2802bba22c5SMike Galbraith }, 28177e54a1fSIngo Molnar #ifdef CONFIG_SCHED_DEBUG 28277e54a1fSIngo Molnar { 283b2be5e96SPeter Zijlstra .procname = "sched_min_granularity_ns", 284b2be5e96SPeter Zijlstra .data = &sysctl_sched_min_granularity, 28577e54a1fSIngo Molnar .maxlen = sizeof(unsigned int), 28677e54a1fSIngo Molnar .mode = 0644, 287702a7c76SLinus Torvalds .proc_handler = sched_proc_update_handler, 288b2be5e96SPeter Zijlstra .extra1 = &min_sched_granularity_ns, 289b2be5e96SPeter Zijlstra .extra2 = &max_sched_granularity_ns, 29077e54a1fSIngo Molnar }, 29177e54a1fSIngo Molnar { 29221805085SPeter Zijlstra .procname = "sched_latency_ns", 29321805085SPeter Zijlstra .data = &sysctl_sched_latency, 29421805085SPeter Zijlstra .maxlen = sizeof(unsigned int), 29521805085SPeter Zijlstra .mode = 0644, 296702a7c76SLinus Torvalds .proc_handler = sched_proc_update_handler, 29721805085SPeter Zijlstra .extra1 = &min_sched_granularity_ns, 29821805085SPeter Zijlstra .extra2 = &max_sched_granularity_ns, 29921805085SPeter Zijlstra }, 30021805085SPeter Zijlstra { 30177e54a1fSIngo Molnar .procname = "sched_wakeup_granularity_ns", 30277e54a1fSIngo Molnar .data = &sysctl_sched_wakeup_granularity, 30377e54a1fSIngo Molnar .maxlen = sizeof(unsigned int), 30477e54a1fSIngo Molnar .mode = 0644, 305702a7c76SLinus Torvalds .proc_handler = sched_proc_update_handler, 30677e54a1fSIngo Molnar .extra1 = &min_wakeup_granularity_ns, 30777e54a1fSIngo Molnar .extra2 = &max_wakeup_granularity_ns, 30877e54a1fSIngo Molnar }, 30977e54a1fSIngo Molnar { 3101983a922SChristian Ehrhardt .procname = "sched_tunable_scaling", 3111983a922SChristian Ehrhardt .data = &sysctl_sched_tunable_scaling, 3121983a922SChristian Ehrhardt .maxlen = sizeof(enum sched_tunable_scaling), 3131983a922SChristian Ehrhardt .mode = 0644, 314702a7c76SLinus Torvalds .proc_handler = sched_proc_update_handler, 3151983a922SChristian Ehrhardt .extra1 = &min_sched_tunable_scaling, 3161983a922SChristian Ehrhardt .extra2 = &max_sched_tunable_scaling, 3172398f2c6SPeter Zijlstra }, 3182398f2c6SPeter Zijlstra { 319da84d961SIngo Molnar .procname = "sched_migration_cost", 320da84d961SIngo Molnar .data = &sysctl_sched_migration_cost, 321da84d961SIngo Molnar .maxlen = sizeof(unsigned int), 322da84d961SIngo Molnar .mode = 0644, 3236d456111SEric W. Biederman .proc_handler = proc_dointvec, 324da84d961SIngo Molnar }, 325b82d9fddSPeter Zijlstra { 326b82d9fddSPeter Zijlstra .procname = "sched_nr_migrate", 327b82d9fddSPeter Zijlstra .data = &sysctl_sched_nr_migrate, 328b82d9fddSPeter Zijlstra .maxlen = sizeof(unsigned int), 329fa85ae24SPeter Zijlstra .mode = 0644, 3306d456111SEric W. Biederman .proc_handler = proc_dointvec, 331fa85ae24SPeter Zijlstra }, 332cd1bb94bSArun R Bharadwaj { 333e9e9250bSPeter Zijlstra .procname = "sched_time_avg", 334e9e9250bSPeter Zijlstra .data = &sysctl_sched_time_avg, 335e9e9250bSPeter Zijlstra .maxlen = sizeof(unsigned int), 336e9e9250bSPeter Zijlstra .mode = 0644, 3376d456111SEric W. Biederman .proc_handler = proc_dointvec, 338e9e9250bSPeter Zijlstra }, 339e9e9250bSPeter Zijlstra { 340a7a4f8a7SPaul Turner .procname = "sched_shares_window", 341a7a4f8a7SPaul Turner .data = &sysctl_sched_shares_window, 342a7a4f8a7SPaul Turner .maxlen = sizeof(unsigned int), 343a7a4f8a7SPaul Turner .mode = 0644, 344a7a4f8a7SPaul Turner .proc_handler = proc_dointvec, 345a7a4f8a7SPaul Turner }, 346a7a4f8a7SPaul Turner { 347cd1bb94bSArun R Bharadwaj .procname = "timer_migration", 348cd1bb94bSArun R Bharadwaj .data = &sysctl_timer_migration, 349cd1bb94bSArun R Bharadwaj .maxlen = sizeof(unsigned int), 350cd1bb94bSArun R Bharadwaj .mode = 0644, 3516d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 352bfdb4d9fSArun R Bharadwaj .extra1 = &zero, 353bfdb4d9fSArun R Bharadwaj .extra2 = &one, 354cd1bb94bSArun R Bharadwaj }, 3551fc84aaaSPeter Zijlstra #endif 3561799e35dSIngo Molnar { 3579f0c1e56SPeter Zijlstra .procname = "sched_rt_period_us", 3589f0c1e56SPeter Zijlstra .data = &sysctl_sched_rt_period, 3599f0c1e56SPeter Zijlstra .maxlen = sizeof(unsigned int), 3609f0c1e56SPeter Zijlstra .mode = 0644, 3616d456111SEric W. Biederman .proc_handler = sched_rt_handler, 3629f0c1e56SPeter Zijlstra }, 3639f0c1e56SPeter Zijlstra { 3649f0c1e56SPeter Zijlstra .procname = "sched_rt_runtime_us", 3659f0c1e56SPeter Zijlstra .data = &sysctl_sched_rt_runtime, 3669f0c1e56SPeter Zijlstra .maxlen = sizeof(int), 3679f0c1e56SPeter Zijlstra .mode = 0644, 3686d456111SEric W. Biederman .proc_handler = sched_rt_handler, 3699f0c1e56SPeter Zijlstra }, 3705091faa4SMike Galbraith #ifdef CONFIG_SCHED_AUTOGROUP 3715091faa4SMike Galbraith { 3725091faa4SMike Galbraith .procname = "sched_autogroup_enabled", 3735091faa4SMike Galbraith .data = &sysctl_sched_autogroup_enabled, 3745091faa4SMike Galbraith .maxlen = sizeof(unsigned int), 3755091faa4SMike Galbraith .mode = 0644, 3761747b21fSYong Zhang .proc_handler = proc_dointvec_minmax, 3775091faa4SMike Galbraith .extra1 = &zero, 3785091faa4SMike Galbraith .extra2 = &one, 3795091faa4SMike Galbraith }, 3805091faa4SMike Galbraith #endif 381f20786ffSPeter Zijlstra #ifdef CONFIG_PROVE_LOCKING 382f20786ffSPeter Zijlstra { 383f20786ffSPeter Zijlstra .procname = "prove_locking", 384f20786ffSPeter Zijlstra .data = &prove_locking, 385f20786ffSPeter Zijlstra .maxlen = sizeof(int), 386f20786ffSPeter Zijlstra .mode = 0644, 3876d456111SEric W. Biederman .proc_handler = proc_dointvec, 388f20786ffSPeter Zijlstra }, 389f20786ffSPeter Zijlstra #endif 390f20786ffSPeter Zijlstra #ifdef CONFIG_LOCK_STAT 391f20786ffSPeter Zijlstra { 392f20786ffSPeter Zijlstra .procname = "lock_stat", 393f20786ffSPeter Zijlstra .data = &lock_stat, 394f20786ffSPeter Zijlstra .maxlen = sizeof(int), 395f20786ffSPeter Zijlstra .mode = 0644, 3966d456111SEric W. Biederman .proc_handler = proc_dointvec, 397f20786ffSPeter Zijlstra }, 398f20786ffSPeter Zijlstra #endif 39977e54a1fSIngo Molnar { 4001da177e4SLinus Torvalds .procname = "panic", 4011da177e4SLinus Torvalds .data = &panic_timeout, 4021da177e4SLinus Torvalds .maxlen = sizeof(int), 4031da177e4SLinus Torvalds .mode = 0644, 4046d456111SEric W. Biederman .proc_handler = proc_dointvec, 4051da177e4SLinus Torvalds }, 4061da177e4SLinus Torvalds { 4071da177e4SLinus Torvalds .procname = "core_uses_pid", 4081da177e4SLinus Torvalds .data = &core_uses_pid, 4091da177e4SLinus Torvalds .maxlen = sizeof(int), 4101da177e4SLinus Torvalds .mode = 0644, 4116d456111SEric W. Biederman .proc_handler = proc_dointvec, 4121da177e4SLinus Torvalds }, 4131da177e4SLinus Torvalds { 4141da177e4SLinus Torvalds .procname = "core_pattern", 4151da177e4SLinus Torvalds .data = core_pattern, 41671ce92f3SDan Aloni .maxlen = CORENAME_MAX_SIZE, 4171da177e4SLinus Torvalds .mode = 0644, 4186d456111SEric W. Biederman .proc_handler = proc_dostring, 4191da177e4SLinus Torvalds }, 420a293980cSNeil Horman { 421a293980cSNeil Horman .procname = "core_pipe_limit", 422a293980cSNeil Horman .data = &core_pipe_limit, 423a293980cSNeil Horman .maxlen = sizeof(unsigned int), 424a293980cSNeil Horman .mode = 0644, 4256d456111SEric W. Biederman .proc_handler = proc_dointvec, 426a293980cSNeil Horman }, 42734f5a398STheodore Ts'o #ifdef CONFIG_PROC_SYSCTL 4281da177e4SLinus Torvalds { 4291da177e4SLinus Torvalds .procname = "tainted", 43025ddbb18SAndi Kleen .maxlen = sizeof(long), 43134f5a398STheodore Ts'o .mode = 0644, 4326d456111SEric W. Biederman .proc_handler = proc_taint, 4331da177e4SLinus Torvalds }, 43434f5a398STheodore Ts'o #endif 4359745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP 4369745512cSArjan van de Ven { 4379745512cSArjan van de Ven .procname = "latencytop", 4389745512cSArjan van de Ven .data = &latencytop_enabled, 4399745512cSArjan van de Ven .maxlen = sizeof(int), 4409745512cSArjan van de Ven .mode = 0644, 4416d456111SEric W. Biederman .proc_handler = proc_dointvec, 4429745512cSArjan van de Ven }, 4439745512cSArjan van de Ven #endif 4441da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD 4451da177e4SLinus Torvalds { 4461da177e4SLinus Torvalds .procname = "real-root-dev", 4471da177e4SLinus Torvalds .data = &real_root_dev, 4481da177e4SLinus Torvalds .maxlen = sizeof(int), 4491da177e4SLinus Torvalds .mode = 0644, 4506d456111SEric W. Biederman .proc_handler = proc_dointvec, 4511da177e4SLinus Torvalds }, 4521da177e4SLinus Torvalds #endif 45345807a1dSIngo Molnar { 45445807a1dSIngo Molnar .procname = "print-fatal-signals", 45545807a1dSIngo Molnar .data = &print_fatal_signals, 45645807a1dSIngo Molnar .maxlen = sizeof(int), 45745807a1dSIngo Molnar .mode = 0644, 4586d456111SEric W. Biederman .proc_handler = proc_dointvec, 45945807a1dSIngo Molnar }, 46072c57ed5SDavid S. Miller #ifdef CONFIG_SPARC 4611da177e4SLinus Torvalds { 4621da177e4SLinus Torvalds .procname = "reboot-cmd", 4631da177e4SLinus Torvalds .data = reboot_command, 4641da177e4SLinus Torvalds .maxlen = 256, 4651da177e4SLinus Torvalds .mode = 0644, 4666d456111SEric W. Biederman .proc_handler = proc_dostring, 4671da177e4SLinus Torvalds }, 4681da177e4SLinus Torvalds { 4691da177e4SLinus Torvalds .procname = "stop-a", 4701da177e4SLinus Torvalds .data = &stop_a_enabled, 4711da177e4SLinus Torvalds .maxlen = sizeof (int), 4721da177e4SLinus Torvalds .mode = 0644, 4736d456111SEric W. Biederman .proc_handler = proc_dointvec, 4741da177e4SLinus Torvalds }, 4751da177e4SLinus Torvalds { 4761da177e4SLinus Torvalds .procname = "scons-poweroff", 4771da177e4SLinus Torvalds .data = &scons_pwroff, 4781da177e4SLinus Torvalds .maxlen = sizeof (int), 4791da177e4SLinus Torvalds .mode = 0644, 4806d456111SEric W. Biederman .proc_handler = proc_dointvec, 4811da177e4SLinus Torvalds }, 4821da177e4SLinus Torvalds #endif 4830871420fSDavid S. Miller #ifdef CONFIG_SPARC64 4840871420fSDavid S. Miller { 4850871420fSDavid S. Miller .procname = "tsb-ratio", 4860871420fSDavid S. Miller .data = &sysctl_tsb_ratio, 4870871420fSDavid S. Miller .maxlen = sizeof (int), 4880871420fSDavid S. Miller .mode = 0644, 4896d456111SEric W. Biederman .proc_handler = proc_dointvec, 4900871420fSDavid S. Miller }, 4910871420fSDavid S. Miller #endif 4921da177e4SLinus Torvalds #ifdef __hppa__ 4931da177e4SLinus Torvalds { 4941da177e4SLinus Torvalds .procname = "soft-power", 4951da177e4SLinus Torvalds .data = &pwrsw_enabled, 4961da177e4SLinus Torvalds .maxlen = sizeof (int), 4971da177e4SLinus Torvalds .mode = 0644, 4986d456111SEric W. Biederman .proc_handler = proc_dointvec, 4991da177e4SLinus Torvalds }, 5001da177e4SLinus Torvalds { 5011da177e4SLinus Torvalds .procname = "unaligned-trap", 5021da177e4SLinus Torvalds .data = &unaligned_enabled, 5031da177e4SLinus Torvalds .maxlen = sizeof (int), 5041da177e4SLinus Torvalds .mode = 0644, 5056d456111SEric W. Biederman .proc_handler = proc_dointvec, 5061da177e4SLinus Torvalds }, 5071da177e4SLinus Torvalds #endif 5081da177e4SLinus Torvalds { 5091da177e4SLinus Torvalds .procname = "ctrl-alt-del", 5101da177e4SLinus Torvalds .data = &C_A_D, 5111da177e4SLinus Torvalds .maxlen = sizeof(int), 5121da177e4SLinus Torvalds .mode = 0644, 5136d456111SEric W. Biederman .proc_handler = proc_dointvec, 5141da177e4SLinus Torvalds }, 515606576ceSSteven Rostedt #ifdef CONFIG_FUNCTION_TRACER 516b0fc494fSSteven Rostedt { 517b0fc494fSSteven Rostedt .procname = "ftrace_enabled", 518b0fc494fSSteven Rostedt .data = &ftrace_enabled, 519b0fc494fSSteven Rostedt .maxlen = sizeof(int), 520b0fc494fSSteven Rostedt .mode = 0644, 5216d456111SEric W. Biederman .proc_handler = ftrace_enable_sysctl, 522b0fc494fSSteven Rostedt }, 523b0fc494fSSteven Rostedt #endif 524f38f1d2aSSteven Rostedt #ifdef CONFIG_STACK_TRACER 525f38f1d2aSSteven Rostedt { 526f38f1d2aSSteven Rostedt .procname = "stack_tracer_enabled", 527f38f1d2aSSteven Rostedt .data = &stack_tracer_enabled, 528f38f1d2aSSteven Rostedt .maxlen = sizeof(int), 529f38f1d2aSSteven Rostedt .mode = 0644, 5306d456111SEric W. Biederman .proc_handler = stack_trace_sysctl, 531f38f1d2aSSteven Rostedt }, 532f38f1d2aSSteven Rostedt #endif 533944ac425SSteven Rostedt #ifdef CONFIG_TRACING 534944ac425SSteven Rostedt { 5353299b4ddSPeter Zijlstra .procname = "ftrace_dump_on_oops", 536944ac425SSteven Rostedt .data = &ftrace_dump_on_oops, 537944ac425SSteven Rostedt .maxlen = sizeof(int), 538944ac425SSteven Rostedt .mode = 0644, 5396d456111SEric W. Biederman .proc_handler = proc_dointvec, 540944ac425SSteven Rostedt }, 541944ac425SSteven Rostedt #endif 542a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES 5431da177e4SLinus Torvalds { 5441da177e4SLinus Torvalds .procname = "modprobe", 5451da177e4SLinus Torvalds .data = &modprobe_path, 5461da177e4SLinus Torvalds .maxlen = KMOD_PATH_LEN, 5471da177e4SLinus Torvalds .mode = 0644, 5486d456111SEric W. Biederman .proc_handler = proc_dostring, 5491da177e4SLinus Torvalds }, 5503d43321bSKees Cook { 5513d43321bSKees Cook .procname = "modules_disabled", 5523d43321bSKees Cook .data = &modules_disabled, 5533d43321bSKees Cook .maxlen = sizeof(int), 5543d43321bSKees Cook .mode = 0644, 5553d43321bSKees Cook /* only handle a transition from default "0" to "1" */ 5566d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 5573d43321bSKees Cook .extra1 = &one, 5583d43321bSKees Cook .extra2 = &one, 5593d43321bSKees Cook }, 5601da177e4SLinus Torvalds #endif 56194f17cd7SIan Abbott #ifdef CONFIG_HOTPLUG 5621da177e4SLinus Torvalds { 5631da177e4SLinus Torvalds .procname = "hotplug", 564312c004dSKay Sievers .data = &uevent_helper, 565312c004dSKay Sievers .maxlen = UEVENT_HELPER_PATH_LEN, 5661da177e4SLinus Torvalds .mode = 0644, 5676d456111SEric W. Biederman .proc_handler = proc_dostring, 5681da177e4SLinus Torvalds }, 5691da177e4SLinus Torvalds #endif 5701da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG 5711da177e4SLinus Torvalds { 5721da177e4SLinus Torvalds .procname = "sg-big-buff", 5731da177e4SLinus Torvalds .data = &sg_big_buff, 5741da177e4SLinus Torvalds .maxlen = sizeof (int), 5751da177e4SLinus Torvalds .mode = 0444, 5766d456111SEric W. Biederman .proc_handler = proc_dointvec, 5771da177e4SLinus Torvalds }, 5781da177e4SLinus Torvalds #endif 5791da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT 5801da177e4SLinus Torvalds { 5811da177e4SLinus Torvalds .procname = "acct", 5821da177e4SLinus Torvalds .data = &acct_parm, 5831da177e4SLinus Torvalds .maxlen = 3*sizeof(int), 5841da177e4SLinus Torvalds .mode = 0644, 5856d456111SEric W. Biederman .proc_handler = proc_dointvec, 5861da177e4SLinus Torvalds }, 5871da177e4SLinus Torvalds #endif 5881da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ 5891da177e4SLinus Torvalds { 5901da177e4SLinus Torvalds .procname = "sysrq", 5915d6f647fSIngo Molnar .data = &__sysrq_enabled, 5921da177e4SLinus Torvalds .maxlen = sizeof (int), 5931da177e4SLinus Torvalds .mode = 0644, 59497f5f0cdSDmitry Torokhov .proc_handler = sysrq_sysctl_handler, 5951da177e4SLinus Torvalds }, 5961da177e4SLinus Torvalds #endif 597d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL 5981da177e4SLinus Torvalds { 5991da177e4SLinus Torvalds .procname = "cad_pid", 6009ec52099SCedric Le Goater .data = NULL, 6011da177e4SLinus Torvalds .maxlen = sizeof (int), 6021da177e4SLinus Torvalds .mode = 0600, 6036d456111SEric W. Biederman .proc_handler = proc_do_cad_pid, 6041da177e4SLinus Torvalds }, 605d6f8ff73SRandy Dunlap #endif 6061da177e4SLinus Torvalds { 6071da177e4SLinus Torvalds .procname = "threads-max", 6081da177e4SLinus Torvalds .data = &max_threads, 6091da177e4SLinus Torvalds .maxlen = sizeof(int), 6101da177e4SLinus Torvalds .mode = 0644, 6116d456111SEric W. Biederman .proc_handler = proc_dointvec, 6121da177e4SLinus Torvalds }, 6131da177e4SLinus Torvalds { 6141da177e4SLinus Torvalds .procname = "random", 6151da177e4SLinus Torvalds .mode = 0555, 6161da177e4SLinus Torvalds .child = random_table, 6171da177e4SLinus Torvalds }, 6181da177e4SLinus Torvalds { 6191da177e4SLinus Torvalds .procname = "overflowuid", 6201da177e4SLinus Torvalds .data = &overflowuid, 6211da177e4SLinus Torvalds .maxlen = sizeof(int), 6221da177e4SLinus Torvalds .mode = 0644, 6236d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 6241da177e4SLinus Torvalds .extra1 = &minolduid, 6251da177e4SLinus Torvalds .extra2 = &maxolduid, 6261da177e4SLinus Torvalds }, 6271da177e4SLinus Torvalds { 6281da177e4SLinus Torvalds .procname = "overflowgid", 6291da177e4SLinus Torvalds .data = &overflowgid, 6301da177e4SLinus Torvalds .maxlen = sizeof(int), 6311da177e4SLinus Torvalds .mode = 0644, 6326d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 6331da177e4SLinus Torvalds .extra1 = &minolduid, 6341da177e4SLinus Torvalds .extra2 = &maxolduid, 6351da177e4SLinus Torvalds }, 636347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390 6371da177e4SLinus Torvalds #ifdef CONFIG_MATHEMU 6381da177e4SLinus Torvalds { 6391da177e4SLinus Torvalds .procname = "ieee_emulation_warnings", 6401da177e4SLinus Torvalds .data = &sysctl_ieee_emulation_warnings, 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 = "userprocess_debug", 648ab3c68eeSHeiko Carstens .data = &show_unhandled_signals, 6491da177e4SLinus Torvalds .maxlen = sizeof(int), 6501da177e4SLinus Torvalds .mode = 0644, 6516d456111SEric W. Biederman .proc_handler = proc_dointvec, 6521da177e4SLinus Torvalds }, 6531da177e4SLinus Torvalds #endif 6541da177e4SLinus Torvalds { 6551da177e4SLinus Torvalds .procname = "pid_max", 6561da177e4SLinus Torvalds .data = &pid_max, 6571da177e4SLinus Torvalds .maxlen = sizeof (int), 6581da177e4SLinus Torvalds .mode = 0644, 6596d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 6601da177e4SLinus Torvalds .extra1 = &pid_max_min, 6611da177e4SLinus Torvalds .extra2 = &pid_max_max, 6621da177e4SLinus Torvalds }, 6631da177e4SLinus Torvalds { 6641da177e4SLinus Torvalds .procname = "panic_on_oops", 6651da177e4SLinus Torvalds .data = &panic_on_oops, 6661da177e4SLinus Torvalds .maxlen = sizeof(int), 6671da177e4SLinus Torvalds .mode = 0644, 6686d456111SEric W. Biederman .proc_handler = proc_dointvec, 6691da177e4SLinus Torvalds }, 6707ef3d2fdSJoe Perches #if defined CONFIG_PRINTK 6717ef3d2fdSJoe Perches { 6727ef3d2fdSJoe Perches .procname = "printk", 6737ef3d2fdSJoe Perches .data = &console_loglevel, 6747ef3d2fdSJoe Perches .maxlen = 4*sizeof(int), 6757ef3d2fdSJoe Perches .mode = 0644, 6766d456111SEric W. Biederman .proc_handler = proc_dointvec, 6777ef3d2fdSJoe Perches }, 6781da177e4SLinus Torvalds { 6791da177e4SLinus Torvalds .procname = "printk_ratelimit", 680717115e1SDave Young .data = &printk_ratelimit_state.interval, 6811da177e4SLinus Torvalds .maxlen = sizeof(int), 6821da177e4SLinus Torvalds .mode = 0644, 6836d456111SEric W. Biederman .proc_handler = proc_dointvec_jiffies, 6841da177e4SLinus Torvalds }, 6851da177e4SLinus Torvalds { 6861da177e4SLinus Torvalds .procname = "printk_ratelimit_burst", 687717115e1SDave Young .data = &printk_ratelimit_state.burst, 6881da177e4SLinus Torvalds .maxlen = sizeof(int), 6891da177e4SLinus Torvalds .mode = 0644, 6906d456111SEric W. Biederman .proc_handler = proc_dointvec, 6911da177e4SLinus Torvalds }, 692af91322eSDave Young { 693af91322eSDave Young .procname = "printk_delay", 694af91322eSDave Young .data = &printk_delay_msec, 695af91322eSDave Young .maxlen = sizeof(int), 696af91322eSDave Young .mode = 0644, 6976d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 698af91322eSDave Young .extra1 = &zero, 699af91322eSDave Young .extra2 = &ten_thousand, 700af91322eSDave Young }, 7011da177e4SLinus Torvalds { 702eaf06b24SDan Rosenberg .procname = "dmesg_restrict", 703eaf06b24SDan Rosenberg .data = &dmesg_restrict, 704eaf06b24SDan Rosenberg .maxlen = sizeof(int), 705eaf06b24SDan Rosenberg .mode = 0644, 706eaf06b24SDan Rosenberg .proc_handler = proc_dointvec_minmax, 707eaf06b24SDan Rosenberg .extra1 = &zero, 708eaf06b24SDan Rosenberg .extra2 = &one, 709eaf06b24SDan Rosenberg }, 710455cd5abSDan Rosenberg { 711455cd5abSDan Rosenberg .procname = "kptr_restrict", 712455cd5abSDan Rosenberg .data = &kptr_restrict, 713455cd5abSDan Rosenberg .maxlen = sizeof(int), 714455cd5abSDan Rosenberg .mode = 0644, 715*bfdc0b49SRichard Weinberger .proc_handler = proc_dmesg_restrict, 716455cd5abSDan Rosenberg .extra1 = &zero, 717455cd5abSDan Rosenberg .extra2 = &two, 718455cd5abSDan Rosenberg }, 719df6e61d4SJoe Perches #endif 720eaf06b24SDan Rosenberg { 7211da177e4SLinus Torvalds .procname = "ngroups_max", 7221da177e4SLinus Torvalds .data = &ngroups_max, 7231da177e4SLinus Torvalds .maxlen = sizeof (int), 7241da177e4SLinus Torvalds .mode = 0444, 7256d456111SEric W. Biederman .proc_handler = proc_dointvec, 7261da177e4SLinus Torvalds }, 72758687acbSDon Zickus #if defined(CONFIG_LOCKUP_DETECTOR) 728504d7cf1SDon Zickus { 72958687acbSDon Zickus .procname = "watchdog", 73058687acbSDon Zickus .data = &watchdog_enabled, 731504d7cf1SDon Zickus .maxlen = sizeof (int), 732504d7cf1SDon Zickus .mode = 0644, 73358687acbSDon Zickus .proc_handler = proc_dowatchdog_enabled, 73458687acbSDon Zickus }, 73558687acbSDon Zickus { 73658687acbSDon Zickus .procname = "watchdog_thresh", 73758687acbSDon Zickus .data = &softlockup_thresh, 73858687acbSDon Zickus .maxlen = sizeof(int), 73958687acbSDon Zickus .mode = 0644, 74058687acbSDon Zickus .proc_handler = proc_dowatchdog_thresh, 74158687acbSDon Zickus .extra1 = &neg_one, 74258687acbSDon Zickus .extra2 = &sixty, 743504d7cf1SDon Zickus }, 7442508ce18SDon Zickus { 7452508ce18SDon Zickus .procname = "softlockup_panic", 7462508ce18SDon Zickus .data = &softlockup_panic, 7472508ce18SDon Zickus .maxlen = sizeof(int), 7482508ce18SDon Zickus .mode = 0644, 7492508ce18SDon Zickus .proc_handler = proc_dointvec_minmax, 7502508ce18SDon Zickus .extra1 = &zero, 7512508ce18SDon Zickus .extra2 = &one, 7522508ce18SDon Zickus }, 7535dc30558SDon Zickus { 7545dc30558SDon Zickus .procname = "nmi_watchdog", 7555dc30558SDon Zickus .data = &watchdog_enabled, 7565dc30558SDon Zickus .maxlen = sizeof (int), 7575dc30558SDon Zickus .mode = 0644, 7585dc30558SDon Zickus .proc_handler = proc_dowatchdog_enabled, 7595dc30558SDon Zickus }, 7605dc30558SDon Zickus #endif 7615dc30558SDon Zickus #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) 7625dc30558SDon Zickus { 7635dc30558SDon Zickus .procname = "unknown_nmi_panic", 7645dc30558SDon Zickus .data = &unknown_nmi_panic, 7655dc30558SDon Zickus .maxlen = sizeof (int), 7665dc30558SDon Zickus .mode = 0644, 7675dc30558SDon Zickus .proc_handler = proc_dointvec, 7685dc30558SDon Zickus }, 769504d7cf1SDon Zickus #endif 7701da177e4SLinus Torvalds #if defined(CONFIG_X86) 7711da177e4SLinus Torvalds { 7728da5addaSDon Zickus .procname = "panic_on_unrecovered_nmi", 7738da5addaSDon Zickus .data = &panic_on_unrecovered_nmi, 7748da5addaSDon Zickus .maxlen = sizeof(int), 7758da5addaSDon Zickus .mode = 0644, 7766d456111SEric W. Biederman .proc_handler = proc_dointvec, 7778da5addaSDon Zickus }, 7788da5addaSDon Zickus { 7795211a242SKurt Garloff .procname = "panic_on_io_nmi", 7805211a242SKurt Garloff .data = &panic_on_io_nmi, 7815211a242SKurt Garloff .maxlen = sizeof(int), 7825211a242SKurt Garloff .mode = 0644, 7836d456111SEric W. Biederman .proc_handler = proc_dointvec, 7845211a242SKurt Garloff }, 7855211a242SKurt Garloff { 7861da177e4SLinus Torvalds .procname = "bootloader_type", 7871da177e4SLinus Torvalds .data = &bootloader_type, 7881da177e4SLinus Torvalds .maxlen = sizeof (int), 7891da177e4SLinus Torvalds .mode = 0444, 7906d456111SEric W. Biederman .proc_handler = proc_dointvec, 7911da177e4SLinus Torvalds }, 7920741f4d2SChuck Ebbert { 7935031296cSH. Peter Anvin .procname = "bootloader_version", 7945031296cSH. Peter Anvin .data = &bootloader_version, 7955031296cSH. Peter Anvin .maxlen = sizeof (int), 7965031296cSH. Peter Anvin .mode = 0444, 7976d456111SEric W. Biederman .proc_handler = proc_dointvec, 7985031296cSH. Peter Anvin }, 7995031296cSH. Peter Anvin { 8000741f4d2SChuck Ebbert .procname = "kstack_depth_to_print", 8010741f4d2SChuck Ebbert .data = &kstack_depth_to_print, 8020741f4d2SChuck Ebbert .maxlen = sizeof(int), 8030741f4d2SChuck Ebbert .mode = 0644, 8046d456111SEric W. Biederman .proc_handler = proc_dointvec, 8050741f4d2SChuck Ebbert }, 8066e7c4025SIngo Molnar { 8076e7c4025SIngo Molnar .procname = "io_delay_type", 8086e7c4025SIngo Molnar .data = &io_delay_type, 8096e7c4025SIngo Molnar .maxlen = sizeof(int), 8106e7c4025SIngo Molnar .mode = 0644, 8116d456111SEric W. Biederman .proc_handler = proc_dointvec, 8126e7c4025SIngo Molnar }, 8131da177e4SLinus Torvalds #endif 8147a9166e3SLuke Yang #if defined(CONFIG_MMU) 8151da177e4SLinus Torvalds { 8161da177e4SLinus Torvalds .procname = "randomize_va_space", 8171da177e4SLinus Torvalds .data = &randomize_va_space, 8181da177e4SLinus Torvalds .maxlen = sizeof(int), 8191da177e4SLinus Torvalds .mode = 0644, 8206d456111SEric W. Biederman .proc_handler = proc_dointvec, 8211da177e4SLinus Torvalds }, 8227a9166e3SLuke Yang #endif 8230152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP) 824951f22d5SMartin Schwidefsky { 825951f22d5SMartin Schwidefsky .procname = "spin_retry", 826951f22d5SMartin Schwidefsky .data = &spin_retry, 827951f22d5SMartin Schwidefsky .maxlen = sizeof (int), 828951f22d5SMartin Schwidefsky .mode = 0644, 8296d456111SEric W. Biederman .proc_handler = proc_dointvec, 830951f22d5SMartin Schwidefsky }, 831951f22d5SMartin Schwidefsky #endif 832673d5b43SLen Brown #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86) 833c255d844SPavel Machek { 834c255d844SPavel Machek .procname = "acpi_video_flags", 83577afcf78SPavel Machek .data = &acpi_realmode_flags, 836c255d844SPavel Machek .maxlen = sizeof (unsigned long), 837c255d844SPavel Machek .mode = 0644, 8386d456111SEric W. Biederman .proc_handler = proc_doulongvec_minmax, 839c255d844SPavel Machek }, 840c255d844SPavel Machek #endif 841d2b176edSJes Sorensen #ifdef CONFIG_IA64 842d2b176edSJes Sorensen { 843d2b176edSJes Sorensen .procname = "ignore-unaligned-usertrap", 844d2b176edSJes Sorensen .data = &no_unaligned_warning, 845d2b176edSJes Sorensen .maxlen = sizeof (int), 846d2b176edSJes Sorensen .mode = 0644, 8476d456111SEric W. Biederman .proc_handler = proc_dointvec, 848d2b176edSJes Sorensen }, 84988fc241fSDoug Chapman { 85088fc241fSDoug Chapman .procname = "unaligned-dump-stack", 85188fc241fSDoug Chapman .data = &unaligned_dump_stack, 85288fc241fSDoug Chapman .maxlen = sizeof (int), 85388fc241fSDoug Chapman .mode = 0644, 8546d456111SEric W. Biederman .proc_handler = proc_dointvec, 85588fc241fSDoug Chapman }, 856d2b176edSJes Sorensen #endif 857e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK 858e162b39aSMandeep Singh Baines { 859e162b39aSMandeep Singh Baines .procname = "hung_task_panic", 860e162b39aSMandeep Singh Baines .data = &sysctl_hung_task_panic, 861e162b39aSMandeep Singh Baines .maxlen = sizeof(int), 862e162b39aSMandeep Singh Baines .mode = 0644, 8636d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 864e162b39aSMandeep Singh Baines .extra1 = &zero, 865e162b39aSMandeep Singh Baines .extra2 = &one, 866e162b39aSMandeep Singh Baines }, 86782a1fcb9SIngo Molnar { 86882a1fcb9SIngo Molnar .procname = "hung_task_check_count", 86982a1fcb9SIngo Molnar .data = &sysctl_hung_task_check_count, 87090739081SIngo Molnar .maxlen = sizeof(unsigned long), 87182a1fcb9SIngo Molnar .mode = 0644, 8726d456111SEric W. Biederman .proc_handler = proc_doulongvec_minmax, 87382a1fcb9SIngo Molnar }, 87482a1fcb9SIngo Molnar { 87582a1fcb9SIngo Molnar .procname = "hung_task_timeout_secs", 87682a1fcb9SIngo Molnar .data = &sysctl_hung_task_timeout_secs, 87790739081SIngo Molnar .maxlen = sizeof(unsigned long), 87882a1fcb9SIngo Molnar .mode = 0644, 8796d456111SEric W. Biederman .proc_handler = proc_dohung_task_timeout_secs, 88082a1fcb9SIngo Molnar }, 88182a1fcb9SIngo Molnar { 88282a1fcb9SIngo Molnar .procname = "hung_task_warnings", 88382a1fcb9SIngo Molnar .data = &sysctl_hung_task_warnings, 88490739081SIngo Molnar .maxlen = sizeof(unsigned long), 88582a1fcb9SIngo Molnar .mode = 0644, 8866d456111SEric W. Biederman .proc_handler = proc_doulongvec_minmax, 88782a1fcb9SIngo Molnar }, 888c4f3b63fSRavikiran G Thirumalai #endif 889bebfa101SAndi Kleen #ifdef CONFIG_COMPAT 890bebfa101SAndi Kleen { 891bebfa101SAndi Kleen .procname = "compat-log", 892bebfa101SAndi Kleen .data = &compat_log, 893bebfa101SAndi Kleen .maxlen = sizeof (int), 894bebfa101SAndi Kleen .mode = 0644, 8956d456111SEric W. Biederman .proc_handler = proc_dointvec, 896bebfa101SAndi Kleen }, 897bebfa101SAndi Kleen #endif 89823f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES 89923f78d4aSIngo Molnar { 90023f78d4aSIngo Molnar .procname = "max_lock_depth", 90123f78d4aSIngo Molnar .data = &max_lock_depth, 90223f78d4aSIngo Molnar .maxlen = sizeof(int), 90323f78d4aSIngo Molnar .mode = 0644, 9046d456111SEric W. Biederman .proc_handler = proc_dointvec, 90523f78d4aSIngo Molnar }, 90623f78d4aSIngo Molnar #endif 90710a0a8d4SJeremy Fitzhardinge { 90810a0a8d4SJeremy Fitzhardinge .procname = "poweroff_cmd", 90910a0a8d4SJeremy Fitzhardinge .data = &poweroff_cmd, 91010a0a8d4SJeremy Fitzhardinge .maxlen = POWEROFF_CMD_PATH_LEN, 91110a0a8d4SJeremy Fitzhardinge .mode = 0644, 9126d456111SEric W. Biederman .proc_handler = proc_dostring, 91310a0a8d4SJeremy Fitzhardinge }, 9140b77f5bfSDavid Howells #ifdef CONFIG_KEYS 9150b77f5bfSDavid Howells { 9160b77f5bfSDavid Howells .procname = "keys", 9170b77f5bfSDavid Howells .mode = 0555, 9180b77f5bfSDavid Howells .child = key_sysctls, 9190b77f5bfSDavid Howells }, 9200b77f5bfSDavid Howells #endif 92131a72bceSPaul E. McKenney #ifdef CONFIG_RCU_TORTURE_TEST 92231a72bceSPaul E. McKenney { 92331a72bceSPaul E. McKenney .procname = "rcutorture_runnable", 92431a72bceSPaul E. McKenney .data = &rcutorture_runnable, 92531a72bceSPaul E. McKenney .maxlen = sizeof(int), 92631a72bceSPaul E. McKenney .mode = 0644, 9276d456111SEric W. Biederman .proc_handler = proc_dointvec, 92831a72bceSPaul E. McKenney }, 92931a72bceSPaul E. McKenney #endif 930cdd6c482SIngo Molnar #ifdef CONFIG_PERF_EVENTS 9311ccd1549SPeter Zijlstra { 932cdd6c482SIngo Molnar .procname = "perf_event_paranoid", 933cdd6c482SIngo Molnar .data = &sysctl_perf_event_paranoid, 934cdd6c482SIngo Molnar .maxlen = sizeof(sysctl_perf_event_paranoid), 9351ccd1549SPeter Zijlstra .mode = 0644, 9366d456111SEric W. Biederman .proc_handler = proc_dointvec, 9371ccd1549SPeter Zijlstra }, 938c5078f78SPeter Zijlstra { 939cdd6c482SIngo Molnar .procname = "perf_event_mlock_kb", 940cdd6c482SIngo Molnar .data = &sysctl_perf_event_mlock, 941cdd6c482SIngo Molnar .maxlen = sizeof(sysctl_perf_event_mlock), 942c5078f78SPeter Zijlstra .mode = 0644, 9436d456111SEric W. Biederman .proc_handler = proc_dointvec, 944c5078f78SPeter Zijlstra }, 945a78ac325SPeter Zijlstra { 946cdd6c482SIngo Molnar .procname = "perf_event_max_sample_rate", 947cdd6c482SIngo Molnar .data = &sysctl_perf_event_sample_rate, 948cdd6c482SIngo Molnar .maxlen = sizeof(sysctl_perf_event_sample_rate), 949a78ac325SPeter Zijlstra .mode = 0644, 950163ec435SPeter Zijlstra .proc_handler = perf_proc_update_handler, 951a78ac325SPeter Zijlstra }, 9521ccd1549SPeter Zijlstra #endif 953dfec072eSVegard Nossum #ifdef CONFIG_KMEMCHECK 954dfec072eSVegard Nossum { 955dfec072eSVegard Nossum .procname = "kmemcheck", 956dfec072eSVegard Nossum .data = &kmemcheck_enabled, 957dfec072eSVegard Nossum .maxlen = sizeof(int), 958dfec072eSVegard Nossum .mode = 0644, 9596d456111SEric W. Biederman .proc_handler = proc_dointvec, 960dfec072eSVegard Nossum }, 961dfec072eSVegard Nossum #endif 962cb684b5bSJens Axboe #ifdef CONFIG_BLOCK 9635e605b64SJens Axboe { 9645e605b64SJens Axboe .procname = "blk_iopoll", 9655e605b64SJens Axboe .data = &blk_iopoll_enabled, 9665e605b64SJens Axboe .maxlen = sizeof(int), 9675e605b64SJens Axboe .mode = 0644, 9686d456111SEric W. Biederman .proc_handler = proc_dointvec, 9695e605b64SJens Axboe }, 970cb684b5bSJens Axboe #endif 9716fce56ecSEric W. Biederman { } 9721da177e4SLinus Torvalds }; 9731da177e4SLinus Torvalds 974d8217f07SEric W. Biederman static struct ctl_table vm_table[] = { 9751da177e4SLinus Torvalds { 9761da177e4SLinus Torvalds .procname = "overcommit_memory", 9771da177e4SLinus Torvalds .data = &sysctl_overcommit_memory, 9781da177e4SLinus Torvalds .maxlen = sizeof(sysctl_overcommit_memory), 9791da177e4SLinus Torvalds .mode = 0644, 980cb16e95fSPetr Holasek .proc_handler = proc_dointvec_minmax, 981cb16e95fSPetr Holasek .extra1 = &zero, 982cb16e95fSPetr Holasek .extra2 = &two, 9831da177e4SLinus Torvalds }, 9841da177e4SLinus Torvalds { 985fadd8fbdSKAMEZAWA Hiroyuki .procname = "panic_on_oom", 986fadd8fbdSKAMEZAWA Hiroyuki .data = &sysctl_panic_on_oom, 987fadd8fbdSKAMEZAWA Hiroyuki .maxlen = sizeof(sysctl_panic_on_oom), 988fadd8fbdSKAMEZAWA Hiroyuki .mode = 0644, 989cb16e95fSPetr Holasek .proc_handler = proc_dointvec_minmax, 990cb16e95fSPetr Holasek .extra1 = &zero, 991cb16e95fSPetr Holasek .extra2 = &two, 992fadd8fbdSKAMEZAWA Hiroyuki }, 993fadd8fbdSKAMEZAWA Hiroyuki { 994fe071d7eSDavid Rientjes .procname = "oom_kill_allocating_task", 995fe071d7eSDavid Rientjes .data = &sysctl_oom_kill_allocating_task, 996fe071d7eSDavid Rientjes .maxlen = sizeof(sysctl_oom_kill_allocating_task), 997fe071d7eSDavid Rientjes .mode = 0644, 9986d456111SEric W. Biederman .proc_handler = proc_dointvec, 999fe071d7eSDavid Rientjes }, 1000fe071d7eSDavid Rientjes { 1001fef1bdd6SDavid Rientjes .procname = "oom_dump_tasks", 1002fef1bdd6SDavid Rientjes .data = &sysctl_oom_dump_tasks, 1003fef1bdd6SDavid Rientjes .maxlen = sizeof(sysctl_oom_dump_tasks), 1004fef1bdd6SDavid Rientjes .mode = 0644, 10056d456111SEric W. Biederman .proc_handler = proc_dointvec, 1006fef1bdd6SDavid Rientjes }, 1007fef1bdd6SDavid Rientjes { 10081da177e4SLinus Torvalds .procname = "overcommit_ratio", 10091da177e4SLinus Torvalds .data = &sysctl_overcommit_ratio, 10101da177e4SLinus Torvalds .maxlen = sizeof(sysctl_overcommit_ratio), 10111da177e4SLinus Torvalds .mode = 0644, 10126d456111SEric W. Biederman .proc_handler = proc_dointvec, 10131da177e4SLinus Torvalds }, 10141da177e4SLinus Torvalds { 10151da177e4SLinus Torvalds .procname = "page-cluster", 10161da177e4SLinus Torvalds .data = &page_cluster, 10171da177e4SLinus Torvalds .maxlen = sizeof(int), 10181da177e4SLinus Torvalds .mode = 0644, 1019cb16e95fSPetr Holasek .proc_handler = proc_dointvec_minmax, 1020cb16e95fSPetr Holasek .extra1 = &zero, 10211da177e4SLinus Torvalds }, 10221da177e4SLinus Torvalds { 10231da177e4SLinus Torvalds .procname = "dirty_background_ratio", 10241da177e4SLinus Torvalds .data = &dirty_background_ratio, 10251da177e4SLinus Torvalds .maxlen = sizeof(dirty_background_ratio), 10261da177e4SLinus Torvalds .mode = 0644, 10276d456111SEric W. Biederman .proc_handler = dirty_background_ratio_handler, 10281da177e4SLinus Torvalds .extra1 = &zero, 10291da177e4SLinus Torvalds .extra2 = &one_hundred, 10301da177e4SLinus Torvalds }, 10311da177e4SLinus Torvalds { 10322da02997SDavid Rientjes .procname = "dirty_background_bytes", 10332da02997SDavid Rientjes .data = &dirty_background_bytes, 10342da02997SDavid Rientjes .maxlen = sizeof(dirty_background_bytes), 10352da02997SDavid Rientjes .mode = 0644, 10366d456111SEric W. Biederman .proc_handler = dirty_background_bytes_handler, 1037fc3501d4SSven Wegener .extra1 = &one_ul, 10382da02997SDavid Rientjes }, 10392da02997SDavid Rientjes { 10401da177e4SLinus Torvalds .procname = "dirty_ratio", 10411da177e4SLinus Torvalds .data = &vm_dirty_ratio, 10421da177e4SLinus Torvalds .maxlen = sizeof(vm_dirty_ratio), 10431da177e4SLinus Torvalds .mode = 0644, 10446d456111SEric W. Biederman .proc_handler = dirty_ratio_handler, 10451da177e4SLinus Torvalds .extra1 = &zero, 10461da177e4SLinus Torvalds .extra2 = &one_hundred, 10471da177e4SLinus Torvalds }, 10481da177e4SLinus Torvalds { 10492da02997SDavid Rientjes .procname = "dirty_bytes", 10502da02997SDavid Rientjes .data = &vm_dirty_bytes, 10512da02997SDavid Rientjes .maxlen = sizeof(vm_dirty_bytes), 10522da02997SDavid Rientjes .mode = 0644, 10536d456111SEric W. Biederman .proc_handler = dirty_bytes_handler, 10549e4a5bdaSAndrea Righi .extra1 = &dirty_bytes_min, 10552da02997SDavid Rientjes }, 10562da02997SDavid Rientjes { 10571da177e4SLinus Torvalds .procname = "dirty_writeback_centisecs", 1058f6ef9438SBart Samwel .data = &dirty_writeback_interval, 1059f6ef9438SBart Samwel .maxlen = sizeof(dirty_writeback_interval), 10601da177e4SLinus Torvalds .mode = 0644, 10616d456111SEric W. Biederman .proc_handler = dirty_writeback_centisecs_handler, 10621da177e4SLinus Torvalds }, 10631da177e4SLinus Torvalds { 10641da177e4SLinus Torvalds .procname = "dirty_expire_centisecs", 1065f6ef9438SBart Samwel .data = &dirty_expire_interval, 1066f6ef9438SBart Samwel .maxlen = sizeof(dirty_expire_interval), 10671da177e4SLinus Torvalds .mode = 0644, 1068cb16e95fSPetr Holasek .proc_handler = proc_dointvec_minmax, 1069cb16e95fSPetr Holasek .extra1 = &zero, 10701da177e4SLinus Torvalds }, 10711da177e4SLinus Torvalds { 10721da177e4SLinus Torvalds .procname = "nr_pdflush_threads", 10731da177e4SLinus Torvalds .data = &nr_pdflush_threads, 10741da177e4SLinus Torvalds .maxlen = sizeof nr_pdflush_threads, 10751da177e4SLinus Torvalds .mode = 0444 /* read-only*/, 10766d456111SEric W. Biederman .proc_handler = proc_dointvec, 10771da177e4SLinus Torvalds }, 10781da177e4SLinus Torvalds { 10791da177e4SLinus Torvalds .procname = "swappiness", 10801da177e4SLinus Torvalds .data = &vm_swappiness, 10811da177e4SLinus Torvalds .maxlen = sizeof(vm_swappiness), 10821da177e4SLinus Torvalds .mode = 0644, 10836d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 10841da177e4SLinus Torvalds .extra1 = &zero, 10851da177e4SLinus Torvalds .extra2 = &one_hundred, 10861da177e4SLinus Torvalds }, 10871da177e4SLinus Torvalds #ifdef CONFIG_HUGETLB_PAGE 10881da177e4SLinus Torvalds { 10891da177e4SLinus Torvalds .procname = "nr_hugepages", 1090e5ff2159SAndi Kleen .data = NULL, 10911da177e4SLinus Torvalds .maxlen = sizeof(unsigned long), 10921da177e4SLinus Torvalds .mode = 0644, 10936d456111SEric W. Biederman .proc_handler = hugetlb_sysctl_handler, 10941da177e4SLinus Torvalds .extra1 = (void *)&hugetlb_zero, 10951da177e4SLinus Torvalds .extra2 = (void *)&hugetlb_infinity, 10961da177e4SLinus Torvalds }, 109706808b08SLee Schermerhorn #ifdef CONFIG_NUMA 109806808b08SLee Schermerhorn { 109906808b08SLee Schermerhorn .procname = "nr_hugepages_mempolicy", 110006808b08SLee Schermerhorn .data = NULL, 110106808b08SLee Schermerhorn .maxlen = sizeof(unsigned long), 110206808b08SLee Schermerhorn .mode = 0644, 110306808b08SLee Schermerhorn .proc_handler = &hugetlb_mempolicy_sysctl_handler, 110406808b08SLee Schermerhorn .extra1 = (void *)&hugetlb_zero, 110506808b08SLee Schermerhorn .extra2 = (void *)&hugetlb_infinity, 110606808b08SLee Schermerhorn }, 110706808b08SLee Schermerhorn #endif 11081da177e4SLinus Torvalds { 11091da177e4SLinus Torvalds .procname = "hugetlb_shm_group", 11101da177e4SLinus Torvalds .data = &sysctl_hugetlb_shm_group, 11111da177e4SLinus Torvalds .maxlen = sizeof(gid_t), 11121da177e4SLinus Torvalds .mode = 0644, 11136d456111SEric W. Biederman .proc_handler = proc_dointvec, 11141da177e4SLinus Torvalds }, 1115396faf03SMel Gorman { 1116396faf03SMel Gorman .procname = "hugepages_treat_as_movable", 1117396faf03SMel Gorman .data = &hugepages_treat_as_movable, 1118396faf03SMel Gorman .maxlen = sizeof(int), 1119396faf03SMel Gorman .mode = 0644, 11206d456111SEric W. Biederman .proc_handler = hugetlb_treat_movable_handler, 1121396faf03SMel Gorman }, 112254f9f80dSAdam Litke { 1123d1c3fb1fSNishanth Aravamudan .procname = "nr_overcommit_hugepages", 1124e5ff2159SAndi Kleen .data = NULL, 1125e5ff2159SAndi Kleen .maxlen = sizeof(unsigned long), 1126d1c3fb1fSNishanth Aravamudan .mode = 0644, 11276d456111SEric W. Biederman .proc_handler = hugetlb_overcommit_handler, 1128e5ff2159SAndi Kleen .extra1 = (void *)&hugetlb_zero, 1129e5ff2159SAndi Kleen .extra2 = (void *)&hugetlb_infinity, 1130d1c3fb1fSNishanth Aravamudan }, 11311da177e4SLinus Torvalds #endif 11321da177e4SLinus Torvalds { 11331da177e4SLinus Torvalds .procname = "lowmem_reserve_ratio", 11341da177e4SLinus Torvalds .data = &sysctl_lowmem_reserve_ratio, 11351da177e4SLinus Torvalds .maxlen = sizeof(sysctl_lowmem_reserve_ratio), 11361da177e4SLinus Torvalds .mode = 0644, 11376d456111SEric W. Biederman .proc_handler = lowmem_reserve_ratio_sysctl_handler, 11381da177e4SLinus Torvalds }, 11391da177e4SLinus Torvalds { 11409d0243bcSAndrew Morton .procname = "drop_caches", 11419d0243bcSAndrew Morton .data = &sysctl_drop_caches, 11429d0243bcSAndrew Morton .maxlen = sizeof(int), 11439d0243bcSAndrew Morton .mode = 0644, 11449d0243bcSAndrew Morton .proc_handler = drop_caches_sysctl_handler, 1145cb16e95fSPetr Holasek .extra1 = &one, 1146cb16e95fSPetr Holasek .extra2 = &three, 11479d0243bcSAndrew Morton }, 114876ab0f53SMel Gorman #ifdef CONFIG_COMPACTION 114976ab0f53SMel Gorman { 115076ab0f53SMel Gorman .procname = "compact_memory", 115176ab0f53SMel Gorman .data = &sysctl_compact_memory, 115276ab0f53SMel Gorman .maxlen = sizeof(int), 115376ab0f53SMel Gorman .mode = 0200, 115476ab0f53SMel Gorman .proc_handler = sysctl_compaction_handler, 115576ab0f53SMel Gorman }, 11565e771905SMel Gorman { 11575e771905SMel Gorman .procname = "extfrag_threshold", 11585e771905SMel Gorman .data = &sysctl_extfrag_threshold, 11595e771905SMel Gorman .maxlen = sizeof(int), 11605e771905SMel Gorman .mode = 0644, 11615e771905SMel Gorman .proc_handler = sysctl_extfrag_handler, 11625e771905SMel Gorman .extra1 = &min_extfrag_threshold, 11635e771905SMel Gorman .extra2 = &max_extfrag_threshold, 11645e771905SMel Gorman }, 11655e771905SMel Gorman 116676ab0f53SMel Gorman #endif /* CONFIG_COMPACTION */ 11679d0243bcSAndrew Morton { 11681da177e4SLinus Torvalds .procname = "min_free_kbytes", 11691da177e4SLinus Torvalds .data = &min_free_kbytes, 11701da177e4SLinus Torvalds .maxlen = sizeof(min_free_kbytes), 11711da177e4SLinus Torvalds .mode = 0644, 11726d456111SEric W. Biederman .proc_handler = min_free_kbytes_sysctl_handler, 11731da177e4SLinus Torvalds .extra1 = &zero, 11741da177e4SLinus Torvalds }, 11758ad4b1fbSRohit Seth { 11768ad4b1fbSRohit Seth .procname = "percpu_pagelist_fraction", 11778ad4b1fbSRohit Seth .data = &percpu_pagelist_fraction, 11788ad4b1fbSRohit Seth .maxlen = sizeof(percpu_pagelist_fraction), 11798ad4b1fbSRohit Seth .mode = 0644, 11806d456111SEric W. Biederman .proc_handler = percpu_pagelist_fraction_sysctl_handler, 11818ad4b1fbSRohit Seth .extra1 = &min_percpu_pagelist_fract, 11828ad4b1fbSRohit Seth }, 11831da177e4SLinus Torvalds #ifdef CONFIG_MMU 11841da177e4SLinus Torvalds { 11851da177e4SLinus Torvalds .procname = "max_map_count", 11861da177e4SLinus Torvalds .data = &sysctl_max_map_count, 11871da177e4SLinus Torvalds .maxlen = sizeof(sysctl_max_map_count), 11881da177e4SLinus Torvalds .mode = 0644, 11893e26120cSWANG Cong .proc_handler = proc_dointvec_minmax, 119070da2340SAmerigo Wang .extra1 = &zero, 11911da177e4SLinus Torvalds }, 1192dd8632a1SPaul Mundt #else 1193dd8632a1SPaul Mundt { 1194dd8632a1SPaul Mundt .procname = "nr_trim_pages", 1195dd8632a1SPaul Mundt .data = &sysctl_nr_trim_pages, 1196dd8632a1SPaul Mundt .maxlen = sizeof(sysctl_nr_trim_pages), 1197dd8632a1SPaul Mundt .mode = 0644, 11986d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 1199dd8632a1SPaul Mundt .extra1 = &zero, 1200dd8632a1SPaul Mundt }, 12011da177e4SLinus Torvalds #endif 12021da177e4SLinus Torvalds { 12031da177e4SLinus Torvalds .procname = "laptop_mode", 12041da177e4SLinus Torvalds .data = &laptop_mode, 12051da177e4SLinus Torvalds .maxlen = sizeof(laptop_mode), 12061da177e4SLinus Torvalds .mode = 0644, 12076d456111SEric W. Biederman .proc_handler = proc_dointvec_jiffies, 12081da177e4SLinus Torvalds }, 12091da177e4SLinus Torvalds { 12101da177e4SLinus Torvalds .procname = "block_dump", 12111da177e4SLinus Torvalds .data = &block_dump, 12121da177e4SLinus Torvalds .maxlen = sizeof(block_dump), 12131da177e4SLinus Torvalds .mode = 0644, 12146d456111SEric W. Biederman .proc_handler = proc_dointvec, 12151da177e4SLinus Torvalds .extra1 = &zero, 12161da177e4SLinus Torvalds }, 12171da177e4SLinus Torvalds { 12181da177e4SLinus Torvalds .procname = "vfs_cache_pressure", 12191da177e4SLinus Torvalds .data = &sysctl_vfs_cache_pressure, 12201da177e4SLinus Torvalds .maxlen = sizeof(sysctl_vfs_cache_pressure), 12211da177e4SLinus Torvalds .mode = 0644, 12226d456111SEric W. Biederman .proc_handler = proc_dointvec, 12231da177e4SLinus Torvalds .extra1 = &zero, 12241da177e4SLinus Torvalds }, 12251da177e4SLinus Torvalds #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT 12261da177e4SLinus Torvalds { 12271da177e4SLinus Torvalds .procname = "legacy_va_layout", 12281da177e4SLinus Torvalds .data = &sysctl_legacy_va_layout, 12291da177e4SLinus Torvalds .maxlen = sizeof(sysctl_legacy_va_layout), 12301da177e4SLinus Torvalds .mode = 0644, 12316d456111SEric W. Biederman .proc_handler = proc_dointvec, 12321da177e4SLinus Torvalds .extra1 = &zero, 12331da177e4SLinus Torvalds }, 12341da177e4SLinus Torvalds #endif 12351743660bSChristoph Lameter #ifdef CONFIG_NUMA 12361743660bSChristoph Lameter { 12371743660bSChristoph Lameter .procname = "zone_reclaim_mode", 12381743660bSChristoph Lameter .data = &zone_reclaim_mode, 12391743660bSChristoph Lameter .maxlen = sizeof(zone_reclaim_mode), 12401743660bSChristoph Lameter .mode = 0644, 12416d456111SEric W. Biederman .proc_handler = proc_dointvec, 1242c84db23cSChristoph Lameter .extra1 = &zero, 12431743660bSChristoph Lameter }, 12449614634fSChristoph Lameter { 12459614634fSChristoph Lameter .procname = "min_unmapped_ratio", 12469614634fSChristoph Lameter .data = &sysctl_min_unmapped_ratio, 12479614634fSChristoph Lameter .maxlen = sizeof(sysctl_min_unmapped_ratio), 12489614634fSChristoph Lameter .mode = 0644, 12496d456111SEric W. Biederman .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler, 12509614634fSChristoph Lameter .extra1 = &zero, 12519614634fSChristoph Lameter .extra2 = &one_hundred, 12529614634fSChristoph Lameter }, 12530ff38490SChristoph Lameter { 12540ff38490SChristoph Lameter .procname = "min_slab_ratio", 12550ff38490SChristoph Lameter .data = &sysctl_min_slab_ratio, 12560ff38490SChristoph Lameter .maxlen = sizeof(sysctl_min_slab_ratio), 12570ff38490SChristoph Lameter .mode = 0644, 12586d456111SEric W. Biederman .proc_handler = sysctl_min_slab_ratio_sysctl_handler, 12590ff38490SChristoph Lameter .extra1 = &zero, 12600ff38490SChristoph Lameter .extra2 = &one_hundred, 12610ff38490SChristoph Lameter }, 12621743660bSChristoph Lameter #endif 126377461ab3SChristoph Lameter #ifdef CONFIG_SMP 126477461ab3SChristoph Lameter { 126577461ab3SChristoph Lameter .procname = "stat_interval", 126677461ab3SChristoph Lameter .data = &sysctl_stat_interval, 126777461ab3SChristoph Lameter .maxlen = sizeof(sysctl_stat_interval), 126877461ab3SChristoph Lameter .mode = 0644, 12696d456111SEric W. Biederman .proc_handler = proc_dointvec_jiffies, 127077461ab3SChristoph Lameter }, 127177461ab3SChristoph Lameter #endif 12726e141546SDavid Howells #ifdef CONFIG_MMU 1273ed032189SEric Paris { 1274ed032189SEric Paris .procname = "mmap_min_addr", 1275788084abSEric Paris .data = &dac_mmap_min_addr, 1276ed032189SEric Paris .maxlen = sizeof(unsigned long), 1277ed032189SEric Paris .mode = 0644, 12786d456111SEric W. Biederman .proc_handler = mmap_min_addr_handler, 1279ed032189SEric Paris }, 12806e141546SDavid Howells #endif 1281f0c0b2b8SKAMEZAWA Hiroyuki #ifdef CONFIG_NUMA 1282f0c0b2b8SKAMEZAWA Hiroyuki { 1283f0c0b2b8SKAMEZAWA Hiroyuki .procname = "numa_zonelist_order", 1284f0c0b2b8SKAMEZAWA Hiroyuki .data = &numa_zonelist_order, 1285f0c0b2b8SKAMEZAWA Hiroyuki .maxlen = NUMA_ZONELIST_ORDER_LEN, 1286f0c0b2b8SKAMEZAWA Hiroyuki .mode = 0644, 12876d456111SEric W. Biederman .proc_handler = numa_zonelist_order_handler, 1288f0c0b2b8SKAMEZAWA Hiroyuki }, 1289f0c0b2b8SKAMEZAWA Hiroyuki #endif 12902b8232ceSAl Viro #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \ 12915c36e657SPaul Mundt (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)) 1292e6e5494cSIngo Molnar { 1293e6e5494cSIngo Molnar .procname = "vdso_enabled", 1294e6e5494cSIngo Molnar .data = &vdso_enabled, 1295e6e5494cSIngo Molnar .maxlen = sizeof(vdso_enabled), 1296e6e5494cSIngo Molnar .mode = 0644, 12976d456111SEric W. Biederman .proc_handler = proc_dointvec, 1298e6e5494cSIngo Molnar .extra1 = &zero, 1299e6e5494cSIngo Molnar }, 1300e6e5494cSIngo Molnar #endif 1301195cf453SBron Gondwana #ifdef CONFIG_HIGHMEM 1302195cf453SBron Gondwana { 1303195cf453SBron Gondwana .procname = "highmem_is_dirtyable", 1304195cf453SBron Gondwana .data = &vm_highmem_is_dirtyable, 1305195cf453SBron Gondwana .maxlen = sizeof(vm_highmem_is_dirtyable), 1306195cf453SBron Gondwana .mode = 0644, 13076d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 1308195cf453SBron Gondwana .extra1 = &zero, 1309195cf453SBron Gondwana .extra2 = &one, 1310195cf453SBron Gondwana }, 1311195cf453SBron Gondwana #endif 13124be6f6bbSPeter Zijlstra { 13134be6f6bbSPeter Zijlstra .procname = "scan_unevictable_pages", 13144be6f6bbSPeter Zijlstra .data = &scan_unevictable_pages, 13154be6f6bbSPeter Zijlstra .maxlen = sizeof(scan_unevictable_pages), 13164be6f6bbSPeter Zijlstra .mode = 0644, 13176d456111SEric W. Biederman .proc_handler = scan_unevictable_handler, 13184be6f6bbSPeter Zijlstra }, 13196a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE 13206a46079cSAndi Kleen { 13216a46079cSAndi Kleen .procname = "memory_failure_early_kill", 13226a46079cSAndi Kleen .data = &sysctl_memory_failure_early_kill, 13236a46079cSAndi Kleen .maxlen = sizeof(sysctl_memory_failure_early_kill), 13246a46079cSAndi Kleen .mode = 0644, 13256d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 13266a46079cSAndi Kleen .extra1 = &zero, 13276a46079cSAndi Kleen .extra2 = &one, 13286a46079cSAndi Kleen }, 13296a46079cSAndi Kleen { 13306a46079cSAndi Kleen .procname = "memory_failure_recovery", 13316a46079cSAndi Kleen .data = &sysctl_memory_failure_recovery, 13326a46079cSAndi Kleen .maxlen = sizeof(sysctl_memory_failure_recovery), 13336a46079cSAndi Kleen .mode = 0644, 13346d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 13356a46079cSAndi Kleen .extra1 = &zero, 13366a46079cSAndi Kleen .extra2 = &one, 13376a46079cSAndi Kleen }, 13386a46079cSAndi Kleen #endif 13396fce56ecSEric W. Biederman { } 13401da177e4SLinus Torvalds }; 13411da177e4SLinus Torvalds 13422abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) 1343d8217f07SEric W. Biederman static struct ctl_table binfmt_misc_table[] = { 13446fce56ecSEric W. Biederman { } 13452abc26fcSEric W. Biederman }; 13462abc26fcSEric W. Biederman #endif 13472abc26fcSEric W. Biederman 1348d8217f07SEric W. Biederman static struct ctl_table fs_table[] = { 13491da177e4SLinus Torvalds { 13501da177e4SLinus Torvalds .procname = "inode-nr", 13511da177e4SLinus Torvalds .data = &inodes_stat, 13521da177e4SLinus Torvalds .maxlen = 2*sizeof(int), 13531da177e4SLinus Torvalds .mode = 0444, 1354cffbc8aaSDave Chinner .proc_handler = proc_nr_inodes, 13551da177e4SLinus Torvalds }, 13561da177e4SLinus Torvalds { 13571da177e4SLinus Torvalds .procname = "inode-state", 13581da177e4SLinus Torvalds .data = &inodes_stat, 13591da177e4SLinus Torvalds .maxlen = 7*sizeof(int), 13601da177e4SLinus Torvalds .mode = 0444, 1361cffbc8aaSDave Chinner .proc_handler = proc_nr_inodes, 13621da177e4SLinus Torvalds }, 13631da177e4SLinus Torvalds { 13641da177e4SLinus Torvalds .procname = "file-nr", 13651da177e4SLinus Torvalds .data = &files_stat, 1366518de9b3SEric Dumazet .maxlen = sizeof(files_stat), 13671da177e4SLinus Torvalds .mode = 0444, 13686d456111SEric W. Biederman .proc_handler = proc_nr_files, 13691da177e4SLinus Torvalds }, 13701da177e4SLinus Torvalds { 13711da177e4SLinus Torvalds .procname = "file-max", 13721da177e4SLinus Torvalds .data = &files_stat.max_files, 1373518de9b3SEric Dumazet .maxlen = sizeof(files_stat.max_files), 13741da177e4SLinus Torvalds .mode = 0644, 1375518de9b3SEric Dumazet .proc_handler = proc_doulongvec_minmax, 13761da177e4SLinus Torvalds }, 13771da177e4SLinus Torvalds { 13789cfe015aSEric Dumazet .procname = "nr_open", 13799cfe015aSEric Dumazet .data = &sysctl_nr_open, 13809cfe015aSEric Dumazet .maxlen = sizeof(int), 13819cfe015aSEric Dumazet .mode = 0644, 13826d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 1383eceea0b3SAl Viro .extra1 = &sysctl_nr_open_min, 1384eceea0b3SAl Viro .extra2 = &sysctl_nr_open_max, 13859cfe015aSEric Dumazet }, 13869cfe015aSEric Dumazet { 13871da177e4SLinus Torvalds .procname = "dentry-state", 13881da177e4SLinus Torvalds .data = &dentry_stat, 13891da177e4SLinus Torvalds .maxlen = 6*sizeof(int), 13901da177e4SLinus Torvalds .mode = 0444, 1391312d3ca8SChristoph Hellwig .proc_handler = proc_nr_dentry, 13921da177e4SLinus Torvalds }, 13931da177e4SLinus Torvalds { 13941da177e4SLinus Torvalds .procname = "overflowuid", 13951da177e4SLinus Torvalds .data = &fs_overflowuid, 13961da177e4SLinus Torvalds .maxlen = sizeof(int), 13971da177e4SLinus Torvalds .mode = 0644, 13986d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 13991da177e4SLinus Torvalds .extra1 = &minolduid, 14001da177e4SLinus Torvalds .extra2 = &maxolduid, 14011da177e4SLinus Torvalds }, 14021da177e4SLinus Torvalds { 14031da177e4SLinus Torvalds .procname = "overflowgid", 14041da177e4SLinus Torvalds .data = &fs_overflowgid, 14051da177e4SLinus Torvalds .maxlen = sizeof(int), 14061da177e4SLinus Torvalds .mode = 0644, 14076d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 14081da177e4SLinus Torvalds .extra1 = &minolduid, 14091da177e4SLinus Torvalds .extra2 = &maxolduid, 14101da177e4SLinus Torvalds }, 1411bfcd17a6SThomas Petazzoni #ifdef CONFIG_FILE_LOCKING 14121da177e4SLinus Torvalds { 14131da177e4SLinus Torvalds .procname = "leases-enable", 14141da177e4SLinus Torvalds .data = &leases_enable, 14151da177e4SLinus Torvalds .maxlen = sizeof(int), 14161da177e4SLinus Torvalds .mode = 0644, 14176d456111SEric W. Biederman .proc_handler = proc_dointvec, 14181da177e4SLinus Torvalds }, 1419bfcd17a6SThomas Petazzoni #endif 14201da177e4SLinus Torvalds #ifdef CONFIG_DNOTIFY 14211da177e4SLinus Torvalds { 14221da177e4SLinus Torvalds .procname = "dir-notify-enable", 14231da177e4SLinus Torvalds .data = &dir_notify_enable, 14241da177e4SLinus Torvalds .maxlen = sizeof(int), 14251da177e4SLinus Torvalds .mode = 0644, 14266d456111SEric W. Biederman .proc_handler = proc_dointvec, 14271da177e4SLinus Torvalds }, 14281da177e4SLinus Torvalds #endif 14291da177e4SLinus Torvalds #ifdef CONFIG_MMU 1430bfcd17a6SThomas Petazzoni #ifdef CONFIG_FILE_LOCKING 14311da177e4SLinus Torvalds { 14321da177e4SLinus Torvalds .procname = "lease-break-time", 14331da177e4SLinus Torvalds .data = &lease_break_time, 14341da177e4SLinus Torvalds .maxlen = sizeof(int), 14351da177e4SLinus Torvalds .mode = 0644, 14366d456111SEric W. Biederman .proc_handler = proc_dointvec, 14371da177e4SLinus Torvalds }, 1438bfcd17a6SThomas Petazzoni #endif 1439ebf3f09cSThomas Petazzoni #ifdef CONFIG_AIO 14401da177e4SLinus Torvalds { 14411da177e4SLinus Torvalds .procname = "aio-nr", 14421da177e4SLinus Torvalds .data = &aio_nr, 14431da177e4SLinus Torvalds .maxlen = sizeof(aio_nr), 14441da177e4SLinus Torvalds .mode = 0444, 14456d456111SEric W. Biederman .proc_handler = proc_doulongvec_minmax, 14461da177e4SLinus Torvalds }, 14471da177e4SLinus Torvalds { 14481da177e4SLinus Torvalds .procname = "aio-max-nr", 14491da177e4SLinus Torvalds .data = &aio_max_nr, 14501da177e4SLinus Torvalds .maxlen = sizeof(aio_max_nr), 14511da177e4SLinus Torvalds .mode = 0644, 14526d456111SEric W. Biederman .proc_handler = proc_doulongvec_minmax, 14531da177e4SLinus Torvalds }, 1454ebf3f09cSThomas Petazzoni #endif /* CONFIG_AIO */ 14552d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER 14560399cb08SRobert Love { 14570399cb08SRobert Love .procname = "inotify", 14580399cb08SRobert Love .mode = 0555, 14590399cb08SRobert Love .child = inotify_table, 14600399cb08SRobert Love }, 14610399cb08SRobert Love #endif 14627ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL 14637ef9964eSDavide Libenzi { 14647ef9964eSDavide Libenzi .procname = "epoll", 14657ef9964eSDavide Libenzi .mode = 0555, 14667ef9964eSDavide Libenzi .child = epoll_table, 14677ef9964eSDavide Libenzi }, 14687ef9964eSDavide Libenzi #endif 14691da177e4SLinus Torvalds #endif 1470d6e71144SAlan Cox { 1471d6e71144SAlan Cox .procname = "suid_dumpable", 1472d6e71144SAlan Cox .data = &suid_dumpable, 1473d6e71144SAlan Cox .maxlen = sizeof(int), 1474d6e71144SAlan Cox .mode = 0644, 14756d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 14768e654fbaSMatthew Wilcox .extra1 = &zero, 14778e654fbaSMatthew Wilcox .extra2 = &two, 1478d6e71144SAlan Cox }, 14792abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) 14802abc26fcSEric W. Biederman { 14812abc26fcSEric W. Biederman .procname = "binfmt_misc", 14822abc26fcSEric W. Biederman .mode = 0555, 14832abc26fcSEric W. Biederman .child = binfmt_misc_table, 14842abc26fcSEric W. Biederman }, 14852abc26fcSEric W. Biederman #endif 1486b492e95bSJens Axboe { 1487ff9da691SJens Axboe .procname = "pipe-max-size", 1488ff9da691SJens Axboe .data = &pipe_max_size, 1489b492e95bSJens Axboe .maxlen = sizeof(int), 1490b492e95bSJens Axboe .mode = 0644, 1491ff9da691SJens Axboe .proc_handler = &pipe_proc_fn, 1492ff9da691SJens Axboe .extra1 = &pipe_min_size, 1493b492e95bSJens Axboe }, 14946fce56ecSEric W. Biederman { } 14951da177e4SLinus Torvalds }; 14961da177e4SLinus Torvalds 1497d8217f07SEric W. Biederman static struct ctl_table debug_table[] = { 1498ab3c68eeSHeiko Carstens #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \ 1499ab3c68eeSHeiko Carstens defined(CONFIG_S390) 1500abd4f750SMasoud Asgharifard Sharbiani { 1501abd4f750SMasoud Asgharifard Sharbiani .procname = "exception-trace", 1502abd4f750SMasoud Asgharifard Sharbiani .data = &show_unhandled_signals, 1503abd4f750SMasoud Asgharifard Sharbiani .maxlen = sizeof(int), 1504abd4f750SMasoud Asgharifard Sharbiani .mode = 0644, 1505abd4f750SMasoud Asgharifard Sharbiani .proc_handler = proc_dointvec 1506abd4f750SMasoud Asgharifard Sharbiani }, 1507abd4f750SMasoud Asgharifard Sharbiani #endif 1508b2be84dfSMasami Hiramatsu #if defined(CONFIG_OPTPROBES) 1509b2be84dfSMasami Hiramatsu { 1510b2be84dfSMasami Hiramatsu .procname = "kprobes-optimization", 1511b2be84dfSMasami Hiramatsu .data = &sysctl_kprobes_optimization, 1512b2be84dfSMasami Hiramatsu .maxlen = sizeof(int), 1513b2be84dfSMasami Hiramatsu .mode = 0644, 1514b2be84dfSMasami Hiramatsu .proc_handler = proc_kprobes_optimization_handler, 1515b2be84dfSMasami Hiramatsu .extra1 = &zero, 1516b2be84dfSMasami Hiramatsu .extra2 = &one, 1517b2be84dfSMasami Hiramatsu }, 1518b2be84dfSMasami Hiramatsu #endif 15196fce56ecSEric W. Biederman { } 15201da177e4SLinus Torvalds }; 15211da177e4SLinus Torvalds 1522d8217f07SEric W. Biederman static struct ctl_table dev_table[] = { 15236fce56ecSEric W. Biederman { } 15241da177e4SLinus Torvalds }; 15251da177e4SLinus Torvalds 1526330d57fbSAl Viro static DEFINE_SPINLOCK(sysctl_lock); 1527330d57fbSAl Viro 1528330d57fbSAl Viro /* called under sysctl_lock */ 1529330d57fbSAl Viro static int use_table(struct ctl_table_header *p) 1530330d57fbSAl Viro { 1531330d57fbSAl Viro if (unlikely(p->unregistering)) 1532330d57fbSAl Viro return 0; 1533330d57fbSAl Viro p->used++; 1534330d57fbSAl Viro return 1; 1535330d57fbSAl Viro } 1536330d57fbSAl Viro 1537330d57fbSAl Viro /* called under sysctl_lock */ 1538330d57fbSAl Viro static void unuse_table(struct ctl_table_header *p) 1539330d57fbSAl Viro { 1540330d57fbSAl Viro if (!--p->used) 1541330d57fbSAl Viro if (unlikely(p->unregistering)) 1542330d57fbSAl Viro complete(p->unregistering); 1543330d57fbSAl Viro } 1544330d57fbSAl Viro 1545330d57fbSAl Viro /* called under sysctl_lock, will reacquire if has to wait */ 1546330d57fbSAl Viro static void start_unregistering(struct ctl_table_header *p) 1547330d57fbSAl Viro { 1548330d57fbSAl Viro /* 1549330d57fbSAl Viro * if p->used is 0, nobody will ever touch that entry again; 1550330d57fbSAl Viro * we'll eliminate all paths to it before dropping sysctl_lock 1551330d57fbSAl Viro */ 1552330d57fbSAl Viro if (unlikely(p->used)) { 1553330d57fbSAl Viro struct completion wait; 1554330d57fbSAl Viro init_completion(&wait); 1555330d57fbSAl Viro p->unregistering = &wait; 1556330d57fbSAl Viro spin_unlock(&sysctl_lock); 1557330d57fbSAl Viro wait_for_completion(&wait); 1558330d57fbSAl Viro spin_lock(&sysctl_lock); 1559f7e6ced4SAl Viro } else { 1560f7e6ced4SAl Viro /* anything non-NULL; we'll never dereference it */ 1561f7e6ced4SAl Viro p->unregistering = ERR_PTR(-EINVAL); 1562330d57fbSAl Viro } 1563330d57fbSAl Viro /* 1564330d57fbSAl Viro * do not remove from the list until nobody holds it; walking the 1565330d57fbSAl Viro * list in do_sysctl() relies on that. 1566330d57fbSAl Viro */ 1567330d57fbSAl Viro list_del_init(&p->ctl_entry); 1568330d57fbSAl Viro } 1569330d57fbSAl Viro 1570f7e6ced4SAl Viro void sysctl_head_get(struct ctl_table_header *head) 1571f7e6ced4SAl Viro { 1572f7e6ced4SAl Viro spin_lock(&sysctl_lock); 1573f7e6ced4SAl Viro head->count++; 1574f7e6ced4SAl Viro spin_unlock(&sysctl_lock); 1575f7e6ced4SAl Viro } 1576f7e6ced4SAl Viro 1577dfef6dcdSAl Viro static void free_head(struct rcu_head *rcu) 1578dfef6dcdSAl Viro { 1579dfef6dcdSAl Viro kfree(container_of(rcu, struct ctl_table_header, rcu)); 1580dfef6dcdSAl Viro } 1581dfef6dcdSAl Viro 1582f7e6ced4SAl Viro void sysctl_head_put(struct ctl_table_header *head) 1583f7e6ced4SAl Viro { 1584f7e6ced4SAl Viro spin_lock(&sysctl_lock); 1585f7e6ced4SAl Viro if (!--head->count) 1586dfef6dcdSAl Viro call_rcu(&head->rcu, free_head); 1587f7e6ced4SAl Viro spin_unlock(&sysctl_lock); 1588f7e6ced4SAl Viro } 1589f7e6ced4SAl Viro 1590f7e6ced4SAl Viro struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head) 1591f7e6ced4SAl Viro { 1592f7e6ced4SAl Viro if (!head) 1593f7e6ced4SAl Viro BUG(); 1594f7e6ced4SAl Viro spin_lock(&sysctl_lock); 1595f7e6ced4SAl Viro if (!use_table(head)) 1596f7e6ced4SAl Viro head = ERR_PTR(-ENOENT); 1597f7e6ced4SAl Viro spin_unlock(&sysctl_lock); 1598f7e6ced4SAl Viro return head; 1599f7e6ced4SAl Viro } 1600f7e6ced4SAl Viro 1601805b5d5eSEric W. Biederman void sysctl_head_finish(struct ctl_table_header *head) 1602805b5d5eSEric W. Biederman { 1603805b5d5eSEric W. Biederman if (!head) 1604805b5d5eSEric W. Biederman return; 1605805b5d5eSEric W. Biederman spin_lock(&sysctl_lock); 1606805b5d5eSEric W. Biederman unuse_table(head); 1607805b5d5eSEric W. Biederman spin_unlock(&sysctl_lock); 1608805b5d5eSEric W. Biederman } 1609805b5d5eSEric W. Biederman 161073455092SAl Viro static struct ctl_table_set * 161173455092SAl Viro lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces) 161273455092SAl Viro { 161373455092SAl Viro struct ctl_table_set *set = &root->default_set; 161473455092SAl Viro if (root->lookup) 161573455092SAl Viro set = root->lookup(root, namespaces); 161673455092SAl Viro return set; 161773455092SAl Viro } 161873455092SAl Viro 1619e51b6ba0SEric W. Biederman static struct list_head * 1620e51b6ba0SEric W. Biederman lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces) 1621805b5d5eSEric W. Biederman { 162273455092SAl Viro struct ctl_table_set *set = lookup_header_set(root, namespaces); 162373455092SAl Viro return &set->list; 1624e51b6ba0SEric W. Biederman } 1625e51b6ba0SEric W. Biederman 1626e51b6ba0SEric W. Biederman struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces, 1627e51b6ba0SEric W. Biederman struct ctl_table_header *prev) 1628e51b6ba0SEric W. Biederman { 1629e51b6ba0SEric W. Biederman struct ctl_table_root *root; 1630e51b6ba0SEric W. Biederman struct list_head *header_list; 1631805b5d5eSEric W. Biederman struct ctl_table_header *head; 1632805b5d5eSEric W. Biederman struct list_head *tmp; 1633e51b6ba0SEric W. Biederman 1634805b5d5eSEric W. Biederman spin_lock(&sysctl_lock); 1635805b5d5eSEric W. Biederman if (prev) { 1636e51b6ba0SEric W. Biederman head = prev; 1637805b5d5eSEric W. Biederman tmp = &prev->ctl_entry; 1638805b5d5eSEric W. Biederman unuse_table(prev); 1639805b5d5eSEric W. Biederman goto next; 1640805b5d5eSEric W. Biederman } 1641805b5d5eSEric W. Biederman tmp = &root_table_header.ctl_entry; 1642805b5d5eSEric W. Biederman for (;;) { 1643805b5d5eSEric W. Biederman head = list_entry(tmp, struct ctl_table_header, ctl_entry); 1644805b5d5eSEric W. Biederman 1645805b5d5eSEric W. Biederman if (!use_table(head)) 1646805b5d5eSEric W. Biederman goto next; 1647805b5d5eSEric W. Biederman spin_unlock(&sysctl_lock); 1648805b5d5eSEric W. Biederman return head; 1649805b5d5eSEric W. Biederman next: 1650e51b6ba0SEric W. Biederman root = head->root; 1651805b5d5eSEric W. Biederman tmp = tmp->next; 1652e51b6ba0SEric W. Biederman header_list = lookup_header_list(root, namespaces); 1653e51b6ba0SEric W. Biederman if (tmp != header_list) 1654e51b6ba0SEric W. Biederman continue; 1655e51b6ba0SEric W. Biederman 1656e51b6ba0SEric W. Biederman do { 1657e51b6ba0SEric W. Biederman root = list_entry(root->root_list.next, 1658e51b6ba0SEric W. Biederman struct ctl_table_root, root_list); 1659e51b6ba0SEric W. Biederman if (root == &sysctl_table_root) 1660e51b6ba0SEric W. Biederman goto out; 1661e51b6ba0SEric W. Biederman header_list = lookup_header_list(root, namespaces); 1662e51b6ba0SEric W. Biederman } while (list_empty(header_list)); 1663e51b6ba0SEric W. Biederman tmp = header_list->next; 1664805b5d5eSEric W. Biederman } 1665e51b6ba0SEric W. Biederman out: 1666805b5d5eSEric W. Biederman spin_unlock(&sysctl_lock); 1667805b5d5eSEric W. Biederman return NULL; 1668805b5d5eSEric W. Biederman } 1669805b5d5eSEric W. Biederman 1670e51b6ba0SEric W. Biederman struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev) 1671e51b6ba0SEric W. Biederman { 1672e51b6ba0SEric W. Biederman return __sysctl_head_next(current->nsproxy, prev); 1673e51b6ba0SEric W. Biederman } 1674e51b6ba0SEric W. Biederman 1675e51b6ba0SEric W. Biederman void register_sysctl_root(struct ctl_table_root *root) 1676e51b6ba0SEric W. Biederman { 1677e51b6ba0SEric W. Biederman spin_lock(&sysctl_lock); 1678e51b6ba0SEric W. Biederman list_add_tail(&root->root_list, &sysctl_table_root.root_list); 1679e51b6ba0SEric W. Biederman spin_unlock(&sysctl_lock); 1680e51b6ba0SEric W. Biederman } 1681e51b6ba0SEric W. Biederman 16821da177e4SLinus Torvalds /* 16831ff007ebSEric W. Biederman * sysctl_perm does NOT grant the superuser all rights automatically, because 16841da177e4SLinus Torvalds * some sysctl variables are readonly even to root. 16851da177e4SLinus Torvalds */ 16861da177e4SLinus Torvalds 16871da177e4SLinus Torvalds static int test_perm(int mode, int op) 16881da177e4SLinus Torvalds { 168976aac0e9SDavid Howells if (!current_euid()) 16901da177e4SLinus Torvalds mode >>= 6; 16911da177e4SLinus Torvalds else if (in_egroup_p(0)) 16921da177e4SLinus Torvalds mode >>= 3; 1693e6305c43SAl Viro if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0) 16941da177e4SLinus Torvalds return 0; 16951da177e4SLinus Torvalds return -EACCES; 16961da177e4SLinus Torvalds } 16971da177e4SLinus Torvalds 1698d7321cd6SPavel Emelyanov int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op) 16991da177e4SLinus Torvalds { 1700d7321cd6SPavel Emelyanov int mode; 1701d7321cd6SPavel Emelyanov 1702d7321cd6SPavel Emelyanov if (root->permissions) 1703d7321cd6SPavel Emelyanov mode = root->permissions(root, current->nsproxy, table); 1704d7321cd6SPavel Emelyanov else 1705d7321cd6SPavel Emelyanov mode = table->mode; 1706d7321cd6SPavel Emelyanov 1707d7321cd6SPavel Emelyanov return test_perm(mode, op); 17081da177e4SLinus Torvalds } 17091da177e4SLinus Torvalds 1710d912b0ccSEric W. Biederman static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table) 1711d912b0ccSEric W. Biederman { 17122315ffa0SEric W. Biederman for (; table->procname; table++) { 1713d912b0ccSEric W. Biederman table->parent = parent; 1714d912b0ccSEric W. Biederman if (table->child) 1715d912b0ccSEric W. Biederman sysctl_set_parent(table, table->child); 1716d912b0ccSEric W. Biederman } 1717d912b0ccSEric W. Biederman } 1718d912b0ccSEric W. Biederman 1719d912b0ccSEric W. Biederman static __init int sysctl_init(void) 1720d912b0ccSEric W. Biederman { 1721d912b0ccSEric W. Biederman sysctl_set_parent(NULL, root_table); 172288f458e4SHolger Schurig #ifdef CONFIG_SYSCTL_SYSCALL_CHECK 1723b3bd3de6SAndi Kleen sysctl_check_table(current->nsproxy, root_table); 172488f458e4SHolger Schurig #endif 1725d912b0ccSEric W. Biederman return 0; 1726d912b0ccSEric W. Biederman } 1727d912b0ccSEric W. Biederman 1728d912b0ccSEric W. Biederman core_initcall(sysctl_init); 1729d912b0ccSEric W. Biederman 1730bfbcf034SAl Viro static struct ctl_table *is_branch_in(struct ctl_table *branch, 1731bfbcf034SAl Viro struct ctl_table *table) 1732ae7edeccSAl Viro { 1733ae7edeccSAl Viro struct ctl_table *p; 1734ae7edeccSAl Viro const char *s = branch->procname; 1735ae7edeccSAl Viro 1736ae7edeccSAl Viro /* branch should have named subdirectory as its first element */ 1737ae7edeccSAl Viro if (!s || !branch->child) 1738bfbcf034SAl Viro return NULL; 1739ae7edeccSAl Viro 1740ae7edeccSAl Viro /* ... and nothing else */ 17412315ffa0SEric W. Biederman if (branch[1].procname) 1742bfbcf034SAl Viro return NULL; 1743ae7edeccSAl Viro 1744ae7edeccSAl Viro /* table should contain subdirectory with the same name */ 17452315ffa0SEric W. Biederman for (p = table; p->procname; p++) { 1746ae7edeccSAl Viro if (!p->child) 1747ae7edeccSAl Viro continue; 1748ae7edeccSAl Viro if (p->procname && strcmp(p->procname, s) == 0) 1749bfbcf034SAl Viro return p; 1750ae7edeccSAl Viro } 1751bfbcf034SAl Viro return NULL; 1752ae7edeccSAl Viro } 1753ae7edeccSAl Viro 1754ae7edeccSAl Viro /* see if attaching q to p would be an improvement */ 1755ae7edeccSAl Viro static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q) 1756ae7edeccSAl Viro { 1757ae7edeccSAl Viro struct ctl_table *to = p->ctl_table, *by = q->ctl_table; 1758bfbcf034SAl Viro struct ctl_table *next; 1759ae7edeccSAl Viro int is_better = 0; 1760ae7edeccSAl Viro int not_in_parent = !p->attached_by; 1761ae7edeccSAl Viro 1762bfbcf034SAl Viro while ((next = is_branch_in(by, to)) != NULL) { 1763ae7edeccSAl Viro if (by == q->attached_by) 1764ae7edeccSAl Viro is_better = 1; 1765ae7edeccSAl Viro if (to == p->attached_by) 1766ae7edeccSAl Viro not_in_parent = 1; 1767ae7edeccSAl Viro by = by->child; 1768bfbcf034SAl Viro to = next->child; 1769ae7edeccSAl Viro } 1770ae7edeccSAl Viro 1771ae7edeccSAl Viro if (is_better && not_in_parent) { 1772ae7edeccSAl Viro q->attached_by = by; 1773ae7edeccSAl Viro q->attached_to = to; 1774ae7edeccSAl Viro q->parent = p; 1775ae7edeccSAl Viro } 1776ae7edeccSAl Viro } 1777ae7edeccSAl Viro 17781da177e4SLinus Torvalds /** 1779e51b6ba0SEric W. Biederman * __register_sysctl_paths - register a sysctl hierarchy 1780e51b6ba0SEric W. Biederman * @root: List of sysctl headers to register on 1781e51b6ba0SEric W. Biederman * @namespaces: Data to compute which lists of sysctl entries are visible 178229e796fdSEric W. Biederman * @path: The path to the directory the sysctl table is in. 17831da177e4SLinus Torvalds * @table: the top-level table structure 17841da177e4SLinus Torvalds * 17851da177e4SLinus Torvalds * Register a sysctl table hierarchy. @table should be a filled in ctl_table 178629e796fdSEric W. Biederman * array. A completely 0 filled entry terminates the table. 17871da177e4SLinus Torvalds * 1788d8217f07SEric W. Biederman * The members of the &struct ctl_table structure are used as follows: 17891da177e4SLinus Torvalds * 17901da177e4SLinus Torvalds * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not 17911da177e4SLinus Torvalds * enter a sysctl file 17921da177e4SLinus Torvalds * 17931da177e4SLinus Torvalds * data - a pointer to data for use by proc_handler 17941da177e4SLinus Torvalds * 17951da177e4SLinus Torvalds * maxlen - the maximum size in bytes of the data 17961da177e4SLinus Torvalds * 17971da177e4SLinus Torvalds * mode - the file permissions for the /proc/sys file, and for sysctl(2) 17981da177e4SLinus Torvalds * 17991da177e4SLinus Torvalds * child - a pointer to the child sysctl table if this entry is a directory, or 18001da177e4SLinus Torvalds * %NULL. 18011da177e4SLinus Torvalds * 18021da177e4SLinus Torvalds * proc_handler - the text handler routine (described below) 18031da177e4SLinus Torvalds * 18041da177e4SLinus Torvalds * de - for internal use by the sysctl routines 18051da177e4SLinus Torvalds * 18061da177e4SLinus Torvalds * extra1, extra2 - extra pointers usable by the proc handler routines 18071da177e4SLinus Torvalds * 18081da177e4SLinus Torvalds * Leaf nodes in the sysctl tree will be represented by a single file 18091da177e4SLinus Torvalds * under /proc; non-leaf nodes will be represented by directories. 18101da177e4SLinus Torvalds * 18111da177e4SLinus Torvalds * sysctl(2) can automatically manage read and write requests through 18121da177e4SLinus Torvalds * the sysctl table. The data and maxlen fields of the ctl_table 18131da177e4SLinus Torvalds * struct enable minimal validation of the values being written to be 18141da177e4SLinus Torvalds * performed, and the mode field allows minimal authentication. 18151da177e4SLinus Torvalds * 18161da177e4SLinus Torvalds * There must be a proc_handler routine for any terminal nodes 18171da177e4SLinus Torvalds * mirrored under /proc/sys (non-terminals are handled by a built-in 18181da177e4SLinus Torvalds * directory handler). Several default handlers are available to 18191da177e4SLinus Torvalds * cover common cases - 18201da177e4SLinus Torvalds * 18211da177e4SLinus Torvalds * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(), 18221da177e4SLinus Torvalds * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(), 18231da177e4SLinus Torvalds * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax() 18241da177e4SLinus Torvalds * 18251da177e4SLinus Torvalds * It is the handler's job to read the input buffer from user memory 18261da177e4SLinus Torvalds * and process it. The handler should return 0 on success. 18271da177e4SLinus Torvalds * 18281da177e4SLinus Torvalds * This routine returns %NULL on a failure to register, and a pointer 18291da177e4SLinus Torvalds * to the table header on success. 18301da177e4SLinus Torvalds */ 1831e51b6ba0SEric W. Biederman struct ctl_table_header *__register_sysctl_paths( 1832e51b6ba0SEric W. Biederman struct ctl_table_root *root, 1833e51b6ba0SEric W. Biederman struct nsproxy *namespaces, 1834e51b6ba0SEric W. Biederman const struct ctl_path *path, struct ctl_table *table) 18351da177e4SLinus Torvalds { 183629e796fdSEric W. Biederman struct ctl_table_header *header; 183729e796fdSEric W. Biederman struct ctl_table *new, **prevp; 183829e796fdSEric W. Biederman unsigned int n, npath; 1839ae7edeccSAl Viro struct ctl_table_set *set; 184029e796fdSEric W. Biederman 184129e796fdSEric W. Biederman /* Count the path components */ 18422315ffa0SEric W. Biederman for (npath = 0; path[npath].procname; ++npath) 184329e796fdSEric W. Biederman ; 184429e796fdSEric W. Biederman 184529e796fdSEric W. Biederman /* 184629e796fdSEric W. Biederman * For each path component, allocate a 2-element ctl_table array. 184729e796fdSEric W. Biederman * The first array element will be filled with the sysctl entry 18482315ffa0SEric W. Biederman * for this, the second will be the sentinel (procname == 0). 184929e796fdSEric W. Biederman * 185029e796fdSEric W. Biederman * We allocate everything in one go so that we don't have to 185129e796fdSEric W. Biederman * worry about freeing additional memory in unregister_sysctl_table. 185229e796fdSEric W. Biederman */ 185329e796fdSEric W. Biederman header = kzalloc(sizeof(struct ctl_table_header) + 185429e796fdSEric W. Biederman (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL); 185529e796fdSEric W. Biederman if (!header) 18561da177e4SLinus Torvalds return NULL; 185729e796fdSEric W. Biederman 185829e796fdSEric W. Biederman new = (struct ctl_table *) (header + 1); 185929e796fdSEric W. Biederman 186029e796fdSEric W. Biederman /* Now connect the dots */ 186129e796fdSEric W. Biederman prevp = &header->ctl_table; 186229e796fdSEric W. Biederman for (n = 0; n < npath; ++n, ++path) { 186329e796fdSEric W. Biederman /* Copy the procname */ 186429e796fdSEric W. Biederman new->procname = path->procname; 186529e796fdSEric W. Biederman new->mode = 0555; 186629e796fdSEric W. Biederman 186729e796fdSEric W. Biederman *prevp = new; 186829e796fdSEric W. Biederman prevp = &new->child; 186929e796fdSEric W. Biederman 187029e796fdSEric W. Biederman new += 2; 187129e796fdSEric W. Biederman } 187229e796fdSEric W. Biederman *prevp = table; 187323eb06deSEric W. Biederman header->ctl_table_arg = table; 187429e796fdSEric W. Biederman 187529e796fdSEric W. Biederman INIT_LIST_HEAD(&header->ctl_entry); 187629e796fdSEric W. Biederman header->used = 0; 187729e796fdSEric W. Biederman header->unregistering = NULL; 1878e51b6ba0SEric W. Biederman header->root = root; 187929e796fdSEric W. Biederman sysctl_set_parent(NULL, header->ctl_table); 1880f7e6ced4SAl Viro header->count = 1; 188188f458e4SHolger Schurig #ifdef CONFIG_SYSCTL_SYSCALL_CHECK 1882e51b6ba0SEric W. Biederman if (sysctl_check_table(namespaces, header->ctl_table)) { 188329e796fdSEric W. Biederman kfree(header); 1884fc6cd25bSEric W. Biederman return NULL; 1885fc6cd25bSEric W. Biederman } 188688f458e4SHolger Schurig #endif 1887330d57fbSAl Viro spin_lock(&sysctl_lock); 188873455092SAl Viro header->set = lookup_header_set(root, namespaces); 1889ae7edeccSAl Viro header->attached_by = header->ctl_table; 1890ae7edeccSAl Viro header->attached_to = root_table; 1891ae7edeccSAl Viro header->parent = &root_table_header; 1892ae7edeccSAl Viro for (set = header->set; set; set = set->parent) { 1893ae7edeccSAl Viro struct ctl_table_header *p; 1894ae7edeccSAl Viro list_for_each_entry(p, &set->list, ctl_entry) { 1895ae7edeccSAl Viro if (p->unregistering) 1896ae7edeccSAl Viro continue; 1897ae7edeccSAl Viro try_attach(p, header); 1898ae7edeccSAl Viro } 1899ae7edeccSAl Viro } 1900ae7edeccSAl Viro header->parent->count++; 190173455092SAl Viro list_add_tail(&header->ctl_entry, &header->set->list); 1902330d57fbSAl Viro spin_unlock(&sysctl_lock); 190329e796fdSEric W. Biederman 190429e796fdSEric W. Biederman return header; 190529e796fdSEric W. Biederman } 190629e796fdSEric W. Biederman 190729e796fdSEric W. Biederman /** 1908e51b6ba0SEric W. Biederman * register_sysctl_table_path - register a sysctl table hierarchy 1909e51b6ba0SEric W. Biederman * @path: The path to the directory the sysctl table is in. 1910e51b6ba0SEric W. Biederman * @table: the top-level table structure 1911e51b6ba0SEric W. Biederman * 1912e51b6ba0SEric W. Biederman * Register a sysctl table hierarchy. @table should be a filled in ctl_table 1913e51b6ba0SEric W. Biederman * array. A completely 0 filled entry terminates the table. 1914e51b6ba0SEric W. Biederman * 1915e51b6ba0SEric W. Biederman * See __register_sysctl_paths for more details. 1916e51b6ba0SEric W. Biederman */ 1917e51b6ba0SEric W. Biederman struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, 1918e51b6ba0SEric W. Biederman struct ctl_table *table) 1919e51b6ba0SEric W. Biederman { 1920e51b6ba0SEric W. Biederman return __register_sysctl_paths(&sysctl_table_root, current->nsproxy, 1921e51b6ba0SEric W. Biederman path, table); 1922e51b6ba0SEric W. Biederman } 1923e51b6ba0SEric W. Biederman 1924e51b6ba0SEric W. Biederman /** 192529e796fdSEric W. Biederman * register_sysctl_table - register a sysctl table hierarchy 192629e796fdSEric W. Biederman * @table: the top-level table structure 192729e796fdSEric W. Biederman * 192829e796fdSEric W. Biederman * Register a sysctl table hierarchy. @table should be a filled in ctl_table 192929e796fdSEric W. Biederman * array. A completely 0 filled entry terminates the table. 193029e796fdSEric W. Biederman * 193129e796fdSEric W. Biederman * See register_sysctl_paths for more details. 193229e796fdSEric W. Biederman */ 193329e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_table(struct ctl_table *table) 193429e796fdSEric W. Biederman { 193529e796fdSEric W. Biederman static const struct ctl_path null_path[] = { {} }; 193629e796fdSEric W. Biederman 193729e796fdSEric W. Biederman return register_sysctl_paths(null_path, table); 19381da177e4SLinus Torvalds } 19391da177e4SLinus Torvalds 19401da177e4SLinus Torvalds /** 19411da177e4SLinus Torvalds * unregister_sysctl_table - unregister a sysctl table hierarchy 19421da177e4SLinus Torvalds * @header: the header returned from register_sysctl_table 19431da177e4SLinus Torvalds * 19441da177e4SLinus Torvalds * Unregisters the sysctl table and all children. proc entries may not 19451da177e4SLinus Torvalds * actually be removed until they are no longer used by anyone. 19461da177e4SLinus Torvalds */ 19471da177e4SLinus Torvalds void unregister_sysctl_table(struct ctl_table_header * header) 19481da177e4SLinus Torvalds { 1949330d57fbSAl Viro might_sleep(); 1950f1dad166SPavel Emelyanov 1951f1dad166SPavel Emelyanov if (header == NULL) 1952f1dad166SPavel Emelyanov return; 1953f1dad166SPavel Emelyanov 1954330d57fbSAl Viro spin_lock(&sysctl_lock); 1955330d57fbSAl Viro start_unregistering(header); 1956ae7edeccSAl Viro if (!--header->parent->count) { 1957ae7edeccSAl Viro WARN_ON(1); 1958dfef6dcdSAl Viro call_rcu(&header->parent->rcu, free_head); 1959ae7edeccSAl Viro } 1960f7e6ced4SAl Viro if (!--header->count) 1961dfef6dcdSAl Viro call_rcu(&header->rcu, free_head); 1962f7e6ced4SAl Viro spin_unlock(&sysctl_lock); 19631da177e4SLinus Torvalds } 19641da177e4SLinus Torvalds 19659043476fSAl Viro int sysctl_is_seen(struct ctl_table_header *p) 19669043476fSAl Viro { 19679043476fSAl Viro struct ctl_table_set *set = p->set; 19689043476fSAl Viro int res; 19699043476fSAl Viro spin_lock(&sysctl_lock); 19709043476fSAl Viro if (p->unregistering) 19719043476fSAl Viro res = 0; 19729043476fSAl Viro else if (!set->is_seen) 19739043476fSAl Viro res = 1; 19749043476fSAl Viro else 19759043476fSAl Viro res = set->is_seen(set); 19769043476fSAl Viro spin_unlock(&sysctl_lock); 19779043476fSAl Viro return res; 19789043476fSAl Viro } 19799043476fSAl Viro 198073455092SAl Viro void setup_sysctl_set(struct ctl_table_set *p, 198173455092SAl Viro struct ctl_table_set *parent, 198273455092SAl Viro int (*is_seen)(struct ctl_table_set *)) 198373455092SAl Viro { 198473455092SAl Viro INIT_LIST_HEAD(&p->list); 198573455092SAl Viro p->parent = parent ? parent : &sysctl_table_root.default_set; 198673455092SAl Viro p->is_seen = is_seen; 198773455092SAl Viro } 198873455092SAl Viro 1989b89a8171SEric W. Biederman #else /* !CONFIG_SYSCTL */ 1990d8217f07SEric W. Biederman struct ctl_table_header *register_sysctl_table(struct ctl_table * table) 1991b89a8171SEric W. Biederman { 1992b89a8171SEric W. Biederman return NULL; 1993b89a8171SEric W. Biederman } 1994b89a8171SEric W. Biederman 199529e796fdSEric W. Biederman struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, 199629e796fdSEric W. Biederman struct ctl_table *table) 199729e796fdSEric W. Biederman { 199829e796fdSEric W. Biederman return NULL; 199929e796fdSEric W. Biederman } 200029e796fdSEric W. Biederman 2001b89a8171SEric W. Biederman void unregister_sysctl_table(struct ctl_table_header * table) 2002b89a8171SEric W. Biederman { 2003b89a8171SEric W. Biederman } 2004b89a8171SEric W. Biederman 200573455092SAl Viro void setup_sysctl_set(struct ctl_table_set *p, 200673455092SAl Viro struct ctl_table_set *parent, 200773455092SAl Viro int (*is_seen)(struct ctl_table_set *)) 200873455092SAl Viro { 200973455092SAl Viro } 201073455092SAl Viro 2011f7e6ced4SAl Viro void sysctl_head_put(struct ctl_table_header *head) 2012f7e6ced4SAl Viro { 2013f7e6ced4SAl Viro } 2014f7e6ced4SAl Viro 2015b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL */ 2016b89a8171SEric W. Biederman 20171da177e4SLinus Torvalds /* 20181da177e4SLinus Torvalds * /proc/sys support 20191da177e4SLinus Torvalds */ 20201da177e4SLinus Torvalds 2021b89a8171SEric W. Biederman #ifdef CONFIG_PROC_SYSCTL 20221da177e4SLinus Torvalds 2023b1ba4dddSAdrian Bunk static int _proc_do_string(void* data, int maxlen, int write, 20248d65af78SAlexey Dobriyan void __user *buffer, 2025b1ba4dddSAdrian Bunk size_t *lenp, loff_t *ppos) 2026f5dd3d6fSSam Vilain { 2027f5dd3d6fSSam Vilain size_t len; 2028f5dd3d6fSSam Vilain char __user *p; 2029f5dd3d6fSSam Vilain char c; 2030f5dd3d6fSSam Vilain 20318d060877SOleg Nesterov if (!data || !maxlen || !*lenp) { 2032f5dd3d6fSSam Vilain *lenp = 0; 2033f5dd3d6fSSam Vilain return 0; 2034f5dd3d6fSSam Vilain } 2035f5dd3d6fSSam Vilain 2036f5dd3d6fSSam Vilain if (write) { 2037f5dd3d6fSSam Vilain len = 0; 2038f5dd3d6fSSam Vilain p = buffer; 2039f5dd3d6fSSam Vilain while (len < *lenp) { 2040f5dd3d6fSSam Vilain if (get_user(c, p++)) 2041f5dd3d6fSSam Vilain return -EFAULT; 2042f5dd3d6fSSam Vilain if (c == 0 || c == '\n') 2043f5dd3d6fSSam Vilain break; 2044f5dd3d6fSSam Vilain len++; 2045f5dd3d6fSSam Vilain } 2046f5dd3d6fSSam Vilain if (len >= maxlen) 2047f5dd3d6fSSam Vilain len = maxlen-1; 2048f5dd3d6fSSam Vilain if(copy_from_user(data, buffer, len)) 2049f5dd3d6fSSam Vilain return -EFAULT; 2050f5dd3d6fSSam Vilain ((char *) data)[len] = 0; 2051f5dd3d6fSSam Vilain *ppos += *lenp; 2052f5dd3d6fSSam Vilain } else { 2053f5dd3d6fSSam Vilain len = strlen(data); 2054f5dd3d6fSSam Vilain if (len > maxlen) 2055f5dd3d6fSSam Vilain len = maxlen; 20568d060877SOleg Nesterov 20578d060877SOleg Nesterov if (*ppos > len) { 20588d060877SOleg Nesterov *lenp = 0; 20598d060877SOleg Nesterov return 0; 20608d060877SOleg Nesterov } 20618d060877SOleg Nesterov 20628d060877SOleg Nesterov data += *ppos; 20638d060877SOleg Nesterov len -= *ppos; 20648d060877SOleg Nesterov 2065f5dd3d6fSSam Vilain if (len > *lenp) 2066f5dd3d6fSSam Vilain len = *lenp; 2067f5dd3d6fSSam Vilain if (len) 2068f5dd3d6fSSam Vilain if(copy_to_user(buffer, data, len)) 2069f5dd3d6fSSam Vilain return -EFAULT; 2070f5dd3d6fSSam Vilain if (len < *lenp) { 2071f5dd3d6fSSam Vilain if(put_user('\n', ((char __user *) buffer) + len)) 2072f5dd3d6fSSam Vilain return -EFAULT; 2073f5dd3d6fSSam Vilain len++; 2074f5dd3d6fSSam Vilain } 2075f5dd3d6fSSam Vilain *lenp = len; 2076f5dd3d6fSSam Vilain *ppos += len; 2077f5dd3d6fSSam Vilain } 2078f5dd3d6fSSam Vilain return 0; 2079f5dd3d6fSSam Vilain } 2080f5dd3d6fSSam Vilain 20811da177e4SLinus Torvalds /** 20821da177e4SLinus Torvalds * proc_dostring - read a string sysctl 20831da177e4SLinus Torvalds * @table: the sysctl table 20841da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 20851da177e4SLinus Torvalds * @buffer: the user buffer 20861da177e4SLinus Torvalds * @lenp: the size of the user buffer 20871da177e4SLinus Torvalds * @ppos: file position 20881da177e4SLinus Torvalds * 20891da177e4SLinus Torvalds * Reads/writes a string from/to the user buffer. If the kernel 20901da177e4SLinus Torvalds * buffer provided is not large enough to hold the string, the 20911da177e4SLinus Torvalds * string is truncated. The copied string is %NULL-terminated. 20921da177e4SLinus Torvalds * If the string is being read by the user process, it is copied 20931da177e4SLinus Torvalds * and a newline '\n' is added. It is truncated if the buffer is 20941da177e4SLinus Torvalds * not large enough. 20951da177e4SLinus Torvalds * 20961da177e4SLinus Torvalds * Returns 0 on success. 20971da177e4SLinus Torvalds */ 20988d65af78SAlexey Dobriyan int proc_dostring(struct ctl_table *table, int write, 20991da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 21001da177e4SLinus Torvalds { 21018d65af78SAlexey Dobriyan return _proc_do_string(table->data, table->maxlen, write, 2102f5dd3d6fSSam Vilain buffer, lenp, ppos); 21031da177e4SLinus Torvalds } 21041da177e4SLinus Torvalds 210500b7c339SAmerigo Wang static size_t proc_skip_spaces(char **buf) 210600b7c339SAmerigo Wang { 210700b7c339SAmerigo Wang size_t ret; 210800b7c339SAmerigo Wang char *tmp = skip_spaces(*buf); 210900b7c339SAmerigo Wang ret = tmp - *buf; 211000b7c339SAmerigo Wang *buf = tmp; 211100b7c339SAmerigo Wang return ret; 211200b7c339SAmerigo Wang } 21131da177e4SLinus Torvalds 21149f977fb7SOctavian Purdila static void proc_skip_char(char **buf, size_t *size, const char v) 21159f977fb7SOctavian Purdila { 21169f977fb7SOctavian Purdila while (*size) { 21179f977fb7SOctavian Purdila if (**buf != v) 21189f977fb7SOctavian Purdila break; 21199f977fb7SOctavian Purdila (*size)--; 21209f977fb7SOctavian Purdila (*buf)++; 21219f977fb7SOctavian Purdila } 21229f977fb7SOctavian Purdila } 21239f977fb7SOctavian Purdila 212400b7c339SAmerigo Wang #define TMPBUFLEN 22 212500b7c339SAmerigo Wang /** 21260fc377bdSRandy Dunlap * proc_get_long - reads an ASCII formatted integer from a user buffer 212700b7c339SAmerigo Wang * 21280fc377bdSRandy Dunlap * @buf: a kernel buffer 21290fc377bdSRandy Dunlap * @size: size of the kernel buffer 21300fc377bdSRandy Dunlap * @val: this is where the number will be stored 21310fc377bdSRandy Dunlap * @neg: set to %TRUE if number is negative 21320fc377bdSRandy Dunlap * @perm_tr: a vector which contains the allowed trailers 21330fc377bdSRandy Dunlap * @perm_tr_len: size of the perm_tr vector 21340fc377bdSRandy Dunlap * @tr: pointer to store the trailer character 213500b7c339SAmerigo Wang * 21360fc377bdSRandy Dunlap * In case of success %0 is returned and @buf and @size are updated with 21370fc377bdSRandy Dunlap * the amount of bytes read. If @tr is non-NULL and a trailing 21380fc377bdSRandy Dunlap * character exists (size is non-zero after returning from this 21390fc377bdSRandy Dunlap * function), @tr is updated with the trailing character. 214000b7c339SAmerigo Wang */ 214100b7c339SAmerigo Wang static int proc_get_long(char **buf, size_t *size, 214200b7c339SAmerigo Wang unsigned long *val, bool *neg, 214300b7c339SAmerigo Wang const char *perm_tr, unsigned perm_tr_len, char *tr) 214400b7c339SAmerigo Wang { 214500b7c339SAmerigo Wang int len; 214600b7c339SAmerigo Wang char *p, tmp[TMPBUFLEN]; 214700b7c339SAmerigo Wang 214800b7c339SAmerigo Wang if (!*size) 214900b7c339SAmerigo Wang return -EINVAL; 215000b7c339SAmerigo Wang 215100b7c339SAmerigo Wang len = *size; 215200b7c339SAmerigo Wang if (len > TMPBUFLEN - 1) 215300b7c339SAmerigo Wang len = TMPBUFLEN - 1; 215400b7c339SAmerigo Wang 215500b7c339SAmerigo Wang memcpy(tmp, *buf, len); 215600b7c339SAmerigo Wang 215700b7c339SAmerigo Wang tmp[len] = 0; 215800b7c339SAmerigo Wang p = tmp; 215900b7c339SAmerigo Wang if (*p == '-' && *size > 1) { 216000b7c339SAmerigo Wang *neg = true; 216100b7c339SAmerigo Wang p++; 216200b7c339SAmerigo Wang } else 216300b7c339SAmerigo Wang *neg = false; 216400b7c339SAmerigo Wang if (!isdigit(*p)) 216500b7c339SAmerigo Wang return -EINVAL; 216600b7c339SAmerigo Wang 216700b7c339SAmerigo Wang *val = simple_strtoul(p, &p, 0); 216800b7c339SAmerigo Wang 216900b7c339SAmerigo Wang len = p - tmp; 217000b7c339SAmerigo Wang 217100b7c339SAmerigo Wang /* We don't know if the next char is whitespace thus we may accept 217200b7c339SAmerigo Wang * invalid integers (e.g. 1234...a) or two integers instead of one 217300b7c339SAmerigo Wang * (e.g. 123...1). So lets not allow such large numbers. */ 217400b7c339SAmerigo Wang if (len == TMPBUFLEN - 1) 217500b7c339SAmerigo Wang return -EINVAL; 217600b7c339SAmerigo Wang 217700b7c339SAmerigo Wang if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len)) 217800b7c339SAmerigo Wang return -EINVAL; 217900b7c339SAmerigo Wang 218000b7c339SAmerigo Wang if (tr && (len < *size)) 218100b7c339SAmerigo Wang *tr = *p; 218200b7c339SAmerigo Wang 218300b7c339SAmerigo Wang *buf += len; 218400b7c339SAmerigo Wang *size -= len; 218500b7c339SAmerigo Wang 218600b7c339SAmerigo Wang return 0; 218700b7c339SAmerigo Wang } 218800b7c339SAmerigo Wang 218900b7c339SAmerigo Wang /** 21900fc377bdSRandy Dunlap * proc_put_long - converts an integer to a decimal ASCII formatted string 219100b7c339SAmerigo Wang * 21920fc377bdSRandy Dunlap * @buf: the user buffer 21930fc377bdSRandy Dunlap * @size: the size of the user buffer 21940fc377bdSRandy Dunlap * @val: the integer to be converted 21950fc377bdSRandy Dunlap * @neg: sign of the number, %TRUE for negative 219600b7c339SAmerigo Wang * 21970fc377bdSRandy Dunlap * In case of success %0 is returned and @buf and @size are updated with 21980fc377bdSRandy Dunlap * the amount of bytes written. 219900b7c339SAmerigo Wang */ 220000b7c339SAmerigo Wang static int proc_put_long(void __user **buf, size_t *size, unsigned long val, 220100b7c339SAmerigo Wang bool neg) 220200b7c339SAmerigo Wang { 220300b7c339SAmerigo Wang int len; 220400b7c339SAmerigo Wang char tmp[TMPBUFLEN], *p = tmp; 220500b7c339SAmerigo Wang 220600b7c339SAmerigo Wang sprintf(p, "%s%lu", neg ? "-" : "", val); 220700b7c339SAmerigo Wang len = strlen(tmp); 220800b7c339SAmerigo Wang if (len > *size) 220900b7c339SAmerigo Wang len = *size; 221000b7c339SAmerigo Wang if (copy_to_user(*buf, tmp, len)) 221100b7c339SAmerigo Wang return -EFAULT; 221200b7c339SAmerigo Wang *size -= len; 221300b7c339SAmerigo Wang *buf += len; 221400b7c339SAmerigo Wang return 0; 221500b7c339SAmerigo Wang } 221600b7c339SAmerigo Wang #undef TMPBUFLEN 221700b7c339SAmerigo Wang 221800b7c339SAmerigo Wang static int proc_put_char(void __user **buf, size_t *size, char c) 221900b7c339SAmerigo Wang { 222000b7c339SAmerigo Wang if (*size) { 222100b7c339SAmerigo Wang char __user **buffer = (char __user **)buf; 222200b7c339SAmerigo Wang if (put_user(c, *buffer)) 222300b7c339SAmerigo Wang return -EFAULT; 222400b7c339SAmerigo Wang (*size)--, (*buffer)++; 222500b7c339SAmerigo Wang *buf = *buffer; 222600b7c339SAmerigo Wang } 222700b7c339SAmerigo Wang return 0; 222800b7c339SAmerigo Wang } 222900b7c339SAmerigo Wang 223000b7c339SAmerigo Wang static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, 22311da177e4SLinus Torvalds int *valp, 22321da177e4SLinus Torvalds int write, void *data) 22331da177e4SLinus Torvalds { 22341da177e4SLinus Torvalds if (write) { 22351da177e4SLinus Torvalds *valp = *negp ? -*lvalp : *lvalp; 22361da177e4SLinus Torvalds } else { 22371da177e4SLinus Torvalds int val = *valp; 22381da177e4SLinus Torvalds if (val < 0) { 223900b7c339SAmerigo Wang *negp = true; 22401da177e4SLinus Torvalds *lvalp = (unsigned long)-val; 22411da177e4SLinus Torvalds } else { 224200b7c339SAmerigo Wang *negp = false; 22431da177e4SLinus Torvalds *lvalp = (unsigned long)val; 22441da177e4SLinus Torvalds } 22451da177e4SLinus Torvalds } 22461da177e4SLinus Torvalds return 0; 22471da177e4SLinus Torvalds } 22481da177e4SLinus Torvalds 224900b7c339SAmerigo Wang static const char proc_wspace_sep[] = { ' ', '\t', '\n' }; 225000b7c339SAmerigo Wang 2251d8217f07SEric W. Biederman static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table, 22528d65af78SAlexey Dobriyan int write, void __user *buffer, 2253fcfbd547SKirill Korotaev size_t *lenp, loff_t *ppos, 225400b7c339SAmerigo Wang int (*conv)(bool *negp, unsigned long *lvalp, int *valp, 22551da177e4SLinus Torvalds int write, void *data), 22561da177e4SLinus Torvalds void *data) 22571da177e4SLinus Torvalds { 225800b7c339SAmerigo Wang int *i, vleft, first = 1, err = 0; 225900b7c339SAmerigo Wang unsigned long page = 0; 226000b7c339SAmerigo Wang size_t left; 226100b7c339SAmerigo Wang char *kbuf; 22621da177e4SLinus Torvalds 226300b7c339SAmerigo Wang if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) { 22641da177e4SLinus Torvalds *lenp = 0; 22651da177e4SLinus Torvalds return 0; 22661da177e4SLinus Torvalds } 22671da177e4SLinus Torvalds 2268fcfbd547SKirill Korotaev i = (int *) tbl_data; 22691da177e4SLinus Torvalds vleft = table->maxlen / sizeof(*i); 22701da177e4SLinus Torvalds left = *lenp; 22711da177e4SLinus Torvalds 22721da177e4SLinus Torvalds if (!conv) 22731da177e4SLinus Torvalds conv = do_proc_dointvec_conv; 22741da177e4SLinus Torvalds 227500b7c339SAmerigo Wang if (write) { 227600b7c339SAmerigo Wang if (left > PAGE_SIZE - 1) 227700b7c339SAmerigo Wang left = PAGE_SIZE - 1; 227800b7c339SAmerigo Wang page = __get_free_page(GFP_TEMPORARY); 227900b7c339SAmerigo Wang kbuf = (char *) page; 228000b7c339SAmerigo Wang if (!kbuf) 228100b7c339SAmerigo Wang return -ENOMEM; 228200b7c339SAmerigo Wang if (copy_from_user(kbuf, buffer, left)) { 228300b7c339SAmerigo Wang err = -EFAULT; 228400b7c339SAmerigo Wang goto free; 228500b7c339SAmerigo Wang } 228600b7c339SAmerigo Wang kbuf[left] = 0; 228700b7c339SAmerigo Wang } 228800b7c339SAmerigo Wang 22891da177e4SLinus Torvalds for (; left && vleft--; i++, first=0) { 229000b7c339SAmerigo Wang unsigned long lval; 229100b7c339SAmerigo Wang bool neg; 229200b7c339SAmerigo Wang 22931da177e4SLinus Torvalds if (write) { 229400b7c339SAmerigo Wang left -= proc_skip_spaces(&kbuf); 229500b7c339SAmerigo Wang 2296563b0467SJ. R. Okajima if (!left) 2297563b0467SJ. R. Okajima break; 229800b7c339SAmerigo Wang err = proc_get_long(&kbuf, &left, &lval, &neg, 229900b7c339SAmerigo Wang proc_wspace_sep, 230000b7c339SAmerigo Wang sizeof(proc_wspace_sep), NULL); 230100b7c339SAmerigo Wang if (err) 23021da177e4SLinus Torvalds break; 230300b7c339SAmerigo Wang if (conv(&neg, &lval, i, 1, data)) { 230400b7c339SAmerigo Wang err = -EINVAL; 230500b7c339SAmerigo Wang break; 23061da177e4SLinus Torvalds } 23071da177e4SLinus Torvalds } else { 230800b7c339SAmerigo Wang if (conv(&neg, &lval, i, 0, data)) { 230900b7c339SAmerigo Wang err = -EINVAL; 231000b7c339SAmerigo Wang break; 231100b7c339SAmerigo Wang } 23121da177e4SLinus Torvalds if (!first) 231300b7c339SAmerigo Wang err = proc_put_char(&buffer, &left, '\t'); 231400b7c339SAmerigo Wang if (err) 23151da177e4SLinus Torvalds break; 231600b7c339SAmerigo Wang err = proc_put_long(&buffer, &left, lval, neg); 231700b7c339SAmerigo Wang if (err) 231800b7c339SAmerigo Wang break; 23191da177e4SLinus Torvalds } 23201da177e4SLinus Torvalds } 23211da177e4SLinus Torvalds 232200b7c339SAmerigo Wang if (!write && !first && left && !err) 232300b7c339SAmerigo Wang err = proc_put_char(&buffer, &left, '\n'); 2324563b0467SJ. R. Okajima if (write && !err && left) 232500b7c339SAmerigo Wang left -= proc_skip_spaces(&kbuf); 232600b7c339SAmerigo Wang free: 23271da177e4SLinus Torvalds if (write) { 232800b7c339SAmerigo Wang free_page(page); 232900b7c339SAmerigo Wang if (first) 233000b7c339SAmerigo Wang return err ? : -EINVAL; 23311da177e4SLinus Torvalds } 23321da177e4SLinus Torvalds *lenp -= left; 23331da177e4SLinus Torvalds *ppos += *lenp; 233400b7c339SAmerigo Wang return err; 23351da177e4SLinus Torvalds } 23361da177e4SLinus Torvalds 23378d65af78SAlexey Dobriyan static int do_proc_dointvec(struct ctl_table *table, int write, 2338fcfbd547SKirill Korotaev void __user *buffer, size_t *lenp, loff_t *ppos, 233900b7c339SAmerigo Wang int (*conv)(bool *negp, unsigned long *lvalp, int *valp, 2340fcfbd547SKirill Korotaev int write, void *data), 2341fcfbd547SKirill Korotaev void *data) 2342fcfbd547SKirill Korotaev { 23438d65af78SAlexey Dobriyan return __do_proc_dointvec(table->data, table, write, 2344fcfbd547SKirill Korotaev buffer, lenp, ppos, conv, data); 2345fcfbd547SKirill Korotaev } 2346fcfbd547SKirill Korotaev 23471da177e4SLinus Torvalds /** 23481da177e4SLinus Torvalds * proc_dointvec - read a vector of integers 23491da177e4SLinus Torvalds * @table: the sysctl table 23501da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 23511da177e4SLinus Torvalds * @buffer: the user buffer 23521da177e4SLinus Torvalds * @lenp: the size of the user buffer 23531da177e4SLinus Torvalds * @ppos: file position 23541da177e4SLinus Torvalds * 23551da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 23561da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 23571da177e4SLinus Torvalds * 23581da177e4SLinus Torvalds * Returns 0 on success. 23591da177e4SLinus Torvalds */ 23608d65af78SAlexey Dobriyan int proc_dointvec(struct ctl_table *table, int write, 23611da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 23621da177e4SLinus Torvalds { 23638d65af78SAlexey Dobriyan return do_proc_dointvec(table,write,buffer,lenp,ppos, 23641da177e4SLinus Torvalds NULL,NULL); 23651da177e4SLinus Torvalds } 23661da177e4SLinus Torvalds 236734f5a398STheodore Ts'o /* 236834f5a398STheodore Ts'o * Taint values can only be increased 236925ddbb18SAndi Kleen * This means we can safely use a temporary. 237034f5a398STheodore Ts'o */ 23718d65af78SAlexey Dobriyan static int proc_taint(struct ctl_table *table, int write, 237234f5a398STheodore Ts'o void __user *buffer, size_t *lenp, loff_t *ppos) 237334f5a398STheodore Ts'o { 237425ddbb18SAndi Kleen struct ctl_table t; 237525ddbb18SAndi Kleen unsigned long tmptaint = get_taint(); 237625ddbb18SAndi Kleen int err; 237734f5a398STheodore Ts'o 237891fcd412SBastian Blank if (write && !capable(CAP_SYS_ADMIN)) 237934f5a398STheodore Ts'o return -EPERM; 238034f5a398STheodore Ts'o 238125ddbb18SAndi Kleen t = *table; 238225ddbb18SAndi Kleen t.data = &tmptaint; 23838d65af78SAlexey Dobriyan err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos); 238425ddbb18SAndi Kleen if (err < 0) 238525ddbb18SAndi Kleen return err; 238625ddbb18SAndi Kleen 238725ddbb18SAndi Kleen if (write) { 238825ddbb18SAndi Kleen /* 238925ddbb18SAndi Kleen * Poor man's atomic or. Not worth adding a primitive 239025ddbb18SAndi Kleen * to everyone's atomic.h for this 239125ddbb18SAndi Kleen */ 239225ddbb18SAndi Kleen int i; 239325ddbb18SAndi Kleen for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) { 239425ddbb18SAndi Kleen if ((tmptaint >> i) & 1) 239525ddbb18SAndi Kleen add_taint(i); 239625ddbb18SAndi Kleen } 239725ddbb18SAndi Kleen } 239825ddbb18SAndi Kleen 239925ddbb18SAndi Kleen return err; 240034f5a398STheodore Ts'o } 240134f5a398STheodore Ts'o 2402*bfdc0b49SRichard Weinberger #ifdef CONFIG_PRINTK 2403*bfdc0b49SRichard Weinberger static int proc_dmesg_restrict(struct ctl_table *table, int write, 2404*bfdc0b49SRichard Weinberger void __user *buffer, size_t *lenp, loff_t *ppos) 2405*bfdc0b49SRichard Weinberger { 2406*bfdc0b49SRichard Weinberger if (write && !capable(CAP_SYS_ADMIN)) 2407*bfdc0b49SRichard Weinberger return -EPERM; 2408*bfdc0b49SRichard Weinberger 2409*bfdc0b49SRichard Weinberger return proc_dointvec_minmax(table, write, buffer, lenp, ppos); 2410*bfdc0b49SRichard Weinberger } 2411*bfdc0b49SRichard Weinberger #endif 2412*bfdc0b49SRichard Weinberger 24131da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param { 24141da177e4SLinus Torvalds int *min; 24151da177e4SLinus Torvalds int *max; 24161da177e4SLinus Torvalds }; 24171da177e4SLinus Torvalds 241800b7c339SAmerigo Wang static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp, 24191da177e4SLinus Torvalds int *valp, 24201da177e4SLinus Torvalds int write, void *data) 24211da177e4SLinus Torvalds { 24221da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param *param = data; 24231da177e4SLinus Torvalds if (write) { 24241da177e4SLinus Torvalds int val = *negp ? -*lvalp : *lvalp; 24251da177e4SLinus Torvalds if ((param->min && *param->min > val) || 24261da177e4SLinus Torvalds (param->max && *param->max < val)) 24271da177e4SLinus Torvalds return -EINVAL; 24281da177e4SLinus Torvalds *valp = val; 24291da177e4SLinus Torvalds } else { 24301da177e4SLinus Torvalds int val = *valp; 24311da177e4SLinus Torvalds if (val < 0) { 243200b7c339SAmerigo Wang *negp = true; 24331da177e4SLinus Torvalds *lvalp = (unsigned long)-val; 24341da177e4SLinus Torvalds } else { 243500b7c339SAmerigo Wang *negp = false; 24361da177e4SLinus Torvalds *lvalp = (unsigned long)val; 24371da177e4SLinus Torvalds } 24381da177e4SLinus Torvalds } 24391da177e4SLinus Torvalds return 0; 24401da177e4SLinus Torvalds } 24411da177e4SLinus Torvalds 24421da177e4SLinus Torvalds /** 24431da177e4SLinus Torvalds * proc_dointvec_minmax - read a vector of integers with min/max values 24441da177e4SLinus Torvalds * @table: the sysctl table 24451da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 24461da177e4SLinus Torvalds * @buffer: the user buffer 24471da177e4SLinus Torvalds * @lenp: the size of the user buffer 24481da177e4SLinus Torvalds * @ppos: file position 24491da177e4SLinus Torvalds * 24501da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 24511da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 24521da177e4SLinus Torvalds * 24531da177e4SLinus Torvalds * This routine will ensure the values are within the range specified by 24541da177e4SLinus Torvalds * table->extra1 (min) and table->extra2 (max). 24551da177e4SLinus Torvalds * 24561da177e4SLinus Torvalds * Returns 0 on success. 24571da177e4SLinus Torvalds */ 24588d65af78SAlexey Dobriyan int proc_dointvec_minmax(struct ctl_table *table, int write, 24591da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 24601da177e4SLinus Torvalds { 24611da177e4SLinus Torvalds struct do_proc_dointvec_minmax_conv_param param = { 24621da177e4SLinus Torvalds .min = (int *) table->extra1, 24631da177e4SLinus Torvalds .max = (int *) table->extra2, 24641da177e4SLinus Torvalds }; 24658d65af78SAlexey Dobriyan return do_proc_dointvec(table, write, buffer, lenp, ppos, 24661da177e4SLinus Torvalds do_proc_dointvec_minmax_conv, ¶m); 24671da177e4SLinus Torvalds } 24681da177e4SLinus Torvalds 2469d8217f07SEric W. Biederman static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write, 24701da177e4SLinus Torvalds void __user *buffer, 24711da177e4SLinus Torvalds size_t *lenp, loff_t *ppos, 24721da177e4SLinus Torvalds unsigned long convmul, 24731da177e4SLinus Torvalds unsigned long convdiv) 24741da177e4SLinus Torvalds { 247500b7c339SAmerigo Wang unsigned long *i, *min, *max; 247600b7c339SAmerigo Wang int vleft, first = 1, err = 0; 247700b7c339SAmerigo Wang unsigned long page = 0; 247800b7c339SAmerigo Wang size_t left; 247900b7c339SAmerigo Wang char *kbuf; 24801da177e4SLinus Torvalds 248100b7c339SAmerigo Wang if (!data || !table->maxlen || !*lenp || (*ppos && !write)) { 24821da177e4SLinus Torvalds *lenp = 0; 24831da177e4SLinus Torvalds return 0; 24841da177e4SLinus Torvalds } 24851da177e4SLinus Torvalds 2486fcfbd547SKirill Korotaev i = (unsigned long *) data; 24871da177e4SLinus Torvalds min = (unsigned long *) table->extra1; 24881da177e4SLinus Torvalds max = (unsigned long *) table->extra2; 24891da177e4SLinus Torvalds vleft = table->maxlen / sizeof(unsigned long); 24901da177e4SLinus Torvalds left = *lenp; 24911da177e4SLinus Torvalds 24921da177e4SLinus Torvalds if (write) { 249300b7c339SAmerigo Wang if (left > PAGE_SIZE - 1) 249400b7c339SAmerigo Wang left = PAGE_SIZE - 1; 249500b7c339SAmerigo Wang page = __get_free_page(GFP_TEMPORARY); 249600b7c339SAmerigo Wang kbuf = (char *) page; 249700b7c339SAmerigo Wang if (!kbuf) 249800b7c339SAmerigo Wang return -ENOMEM; 249900b7c339SAmerigo Wang if (copy_from_user(kbuf, buffer, left)) { 250000b7c339SAmerigo Wang err = -EFAULT; 250100b7c339SAmerigo Wang goto free; 25021da177e4SLinus Torvalds } 250300b7c339SAmerigo Wang kbuf[left] = 0; 25041da177e4SLinus Torvalds } 25051da177e4SLinus Torvalds 250627b3d80aSEric Dumazet for (; left && vleft--; i++, first = 0) { 250700b7c339SAmerigo Wang unsigned long val; 250800b7c339SAmerigo Wang 250900b7c339SAmerigo Wang if (write) { 251000b7c339SAmerigo Wang bool neg; 251100b7c339SAmerigo Wang 251200b7c339SAmerigo Wang left -= proc_skip_spaces(&kbuf); 251300b7c339SAmerigo Wang 251400b7c339SAmerigo Wang err = proc_get_long(&kbuf, &left, &val, &neg, 251500b7c339SAmerigo Wang proc_wspace_sep, 251600b7c339SAmerigo Wang sizeof(proc_wspace_sep), NULL); 251700b7c339SAmerigo Wang if (err) 251800b7c339SAmerigo Wang break; 25191da177e4SLinus Torvalds if (neg) 25201da177e4SLinus Torvalds continue; 25211da177e4SLinus Torvalds if ((min && val < *min) || (max && val > *max)) 25221da177e4SLinus Torvalds continue; 25231da177e4SLinus Torvalds *i = val; 25241da177e4SLinus Torvalds } else { 252500b7c339SAmerigo Wang val = convdiv * (*i) / convmul; 25261da177e4SLinus Torvalds if (!first) 252700b7c339SAmerigo Wang err = proc_put_char(&buffer, &left, '\t'); 252800b7c339SAmerigo Wang err = proc_put_long(&buffer, &left, val, false); 252900b7c339SAmerigo Wang if (err) 253000b7c339SAmerigo Wang break; 25311da177e4SLinus Torvalds } 25321da177e4SLinus Torvalds } 25331da177e4SLinus Torvalds 253400b7c339SAmerigo Wang if (!write && !first && left && !err) 253500b7c339SAmerigo Wang err = proc_put_char(&buffer, &left, '\n'); 253600b7c339SAmerigo Wang if (write && !err) 253700b7c339SAmerigo Wang left -= proc_skip_spaces(&kbuf); 253800b7c339SAmerigo Wang free: 25391da177e4SLinus Torvalds if (write) { 254000b7c339SAmerigo Wang free_page(page); 254100b7c339SAmerigo Wang if (first) 254200b7c339SAmerigo Wang return err ? : -EINVAL; 25431da177e4SLinus Torvalds } 25441da177e4SLinus Torvalds *lenp -= left; 25451da177e4SLinus Torvalds *ppos += *lenp; 254600b7c339SAmerigo Wang return err; 25471da177e4SLinus Torvalds } 25481da177e4SLinus Torvalds 2549d8217f07SEric W. Biederman static int do_proc_doulongvec_minmax(struct ctl_table *table, int write, 2550fcfbd547SKirill Korotaev void __user *buffer, 2551fcfbd547SKirill Korotaev size_t *lenp, loff_t *ppos, 2552fcfbd547SKirill Korotaev unsigned long convmul, 2553fcfbd547SKirill Korotaev unsigned long convdiv) 2554fcfbd547SKirill Korotaev { 2555fcfbd547SKirill Korotaev return __do_proc_doulongvec_minmax(table->data, table, write, 25568d65af78SAlexey Dobriyan buffer, lenp, ppos, convmul, convdiv); 2557fcfbd547SKirill Korotaev } 2558fcfbd547SKirill Korotaev 25591da177e4SLinus Torvalds /** 25601da177e4SLinus Torvalds * proc_doulongvec_minmax - read a vector of long integers with min/max values 25611da177e4SLinus Torvalds * @table: the sysctl table 25621da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 25631da177e4SLinus Torvalds * @buffer: the user buffer 25641da177e4SLinus Torvalds * @lenp: the size of the user buffer 25651da177e4SLinus Torvalds * @ppos: file position 25661da177e4SLinus Torvalds * 25671da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long 25681da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 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 */ 25758d65af78SAlexey Dobriyan int proc_doulongvec_minmax(struct ctl_table *table, int write, 25761da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 25771da177e4SLinus Torvalds { 25788d65af78SAlexey Dobriyan return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l); 25791da177e4SLinus Torvalds } 25801da177e4SLinus Torvalds 25811da177e4SLinus Torvalds /** 25821da177e4SLinus Torvalds * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values 25831da177e4SLinus Torvalds * @table: the sysctl table 25841da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 25851da177e4SLinus Torvalds * @buffer: the user buffer 25861da177e4SLinus Torvalds * @lenp: the size of the user buffer 25871da177e4SLinus Torvalds * @ppos: file position 25881da177e4SLinus Torvalds * 25891da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long 25901da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. The values 25911da177e4SLinus Torvalds * are treated as milliseconds, and converted to jiffies when they are stored. 25921da177e4SLinus Torvalds * 25931da177e4SLinus Torvalds * This routine will ensure the values are within the range specified by 25941da177e4SLinus Torvalds * table->extra1 (min) and table->extra2 (max). 25951da177e4SLinus Torvalds * 25961da177e4SLinus Torvalds * Returns 0 on success. 25971da177e4SLinus Torvalds */ 2598d8217f07SEric W. Biederman int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, 25991da177e4SLinus Torvalds void __user *buffer, 26001da177e4SLinus Torvalds size_t *lenp, loff_t *ppos) 26011da177e4SLinus Torvalds { 26028d65af78SAlexey Dobriyan return do_proc_doulongvec_minmax(table, write, buffer, 26031da177e4SLinus Torvalds lenp, ppos, HZ, 1000l); 26041da177e4SLinus Torvalds } 26051da177e4SLinus Torvalds 26061da177e4SLinus Torvalds 260700b7c339SAmerigo Wang static int do_proc_dointvec_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 (*lvalp > LONG_MAX / HZ) 2613cba9f33dSBart Samwel return 1; 26141da177e4SLinus Torvalds *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ); 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 = lval / HZ; 26261da177e4SLinus Torvalds } 26271da177e4SLinus Torvalds return 0; 26281da177e4SLinus Torvalds } 26291da177e4SLinus Torvalds 263000b7c339SAmerigo Wang static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp, 26311da177e4SLinus Torvalds int *valp, 26321da177e4SLinus Torvalds int write, void *data) 26331da177e4SLinus Torvalds { 26341da177e4SLinus Torvalds if (write) { 2635cba9f33dSBart Samwel if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ) 2636cba9f33dSBart Samwel return 1; 26371da177e4SLinus Torvalds *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp); 26381da177e4SLinus Torvalds } else { 26391da177e4SLinus Torvalds int val = *valp; 26401da177e4SLinus Torvalds unsigned long lval; 26411da177e4SLinus Torvalds if (val < 0) { 264200b7c339SAmerigo Wang *negp = true; 26431da177e4SLinus Torvalds lval = (unsigned long)-val; 26441da177e4SLinus Torvalds } else { 264500b7c339SAmerigo Wang *negp = false; 26461da177e4SLinus Torvalds lval = (unsigned long)val; 26471da177e4SLinus Torvalds } 26481da177e4SLinus Torvalds *lvalp = jiffies_to_clock_t(lval); 26491da177e4SLinus Torvalds } 26501da177e4SLinus Torvalds return 0; 26511da177e4SLinus Torvalds } 26521da177e4SLinus Torvalds 265300b7c339SAmerigo Wang static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp, 26541da177e4SLinus Torvalds int *valp, 26551da177e4SLinus Torvalds int write, void *data) 26561da177e4SLinus Torvalds { 26571da177e4SLinus Torvalds if (write) { 26581da177e4SLinus Torvalds *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp); 26591da177e4SLinus Torvalds } else { 26601da177e4SLinus Torvalds int val = *valp; 26611da177e4SLinus Torvalds unsigned long lval; 26621da177e4SLinus Torvalds if (val < 0) { 266300b7c339SAmerigo Wang *negp = true; 26641da177e4SLinus Torvalds lval = (unsigned long)-val; 26651da177e4SLinus Torvalds } else { 266600b7c339SAmerigo Wang *negp = false; 26671da177e4SLinus Torvalds lval = (unsigned long)val; 26681da177e4SLinus Torvalds } 26691da177e4SLinus Torvalds *lvalp = jiffies_to_msecs(lval); 26701da177e4SLinus Torvalds } 26711da177e4SLinus Torvalds return 0; 26721da177e4SLinus Torvalds } 26731da177e4SLinus Torvalds 26741da177e4SLinus Torvalds /** 26751da177e4SLinus Torvalds * proc_dointvec_jiffies - read a vector of integers as seconds 26761da177e4SLinus Torvalds * @table: the sysctl table 26771da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 26781da177e4SLinus Torvalds * @buffer: the user buffer 26791da177e4SLinus Torvalds * @lenp: the size of the user buffer 26801da177e4SLinus Torvalds * @ppos: file position 26811da177e4SLinus Torvalds * 26821da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 26831da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 26841da177e4SLinus Torvalds * The values read are assumed to be in seconds, and are converted into 26851da177e4SLinus Torvalds * jiffies. 26861da177e4SLinus Torvalds * 26871da177e4SLinus Torvalds * Returns 0 on success. 26881da177e4SLinus Torvalds */ 26898d65af78SAlexey Dobriyan int proc_dointvec_jiffies(struct ctl_table *table, int write, 26901da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 26911da177e4SLinus Torvalds { 26928d65af78SAlexey Dobriyan return do_proc_dointvec(table,write,buffer,lenp,ppos, 26931da177e4SLinus Torvalds do_proc_dointvec_jiffies_conv,NULL); 26941da177e4SLinus Torvalds } 26951da177e4SLinus Torvalds 26961da177e4SLinus Torvalds /** 26971da177e4SLinus Torvalds * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds 26981da177e4SLinus Torvalds * @table: the sysctl table 26991da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 27001da177e4SLinus Torvalds * @buffer: the user buffer 27011da177e4SLinus Torvalds * @lenp: the size of the user buffer 27021e5d5331SRandy Dunlap * @ppos: pointer to the file position 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/USER_HZ seconds, and 27071da177e4SLinus Torvalds * are converted into jiffies. 27081da177e4SLinus Torvalds * 27091da177e4SLinus Torvalds * Returns 0 on success. 27101da177e4SLinus Torvalds */ 27118d65af78SAlexey Dobriyan int proc_dointvec_userhz_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_userhz_jiffies_conv,NULL); 27161da177e4SLinus Torvalds } 27171da177e4SLinus Torvalds 27181da177e4SLinus Torvalds /** 27191da177e4SLinus Torvalds * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds 27201da177e4SLinus Torvalds * @table: the sysctl table 27211da177e4SLinus Torvalds * @write: %TRUE if this is a write to the sysctl file 27221da177e4SLinus Torvalds * @buffer: the user buffer 27231da177e4SLinus Torvalds * @lenp: the size of the user buffer 272467be2dd1SMartin Waitz * @ppos: file position 272567be2dd1SMartin Waitz * @ppos: the current position in the file 27261da177e4SLinus Torvalds * 27271da177e4SLinus Torvalds * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 27281da177e4SLinus Torvalds * values from/to the user buffer, treated as an ASCII string. 27291da177e4SLinus Torvalds * The values read are assumed to be in 1/1000 seconds, and 27301da177e4SLinus Torvalds * are converted into jiffies. 27311da177e4SLinus Torvalds * 27321da177e4SLinus Torvalds * Returns 0 on success. 27331da177e4SLinus Torvalds */ 27348d65af78SAlexey Dobriyan int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, 27351da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 27361da177e4SLinus Torvalds { 27378d65af78SAlexey Dobriyan return do_proc_dointvec(table, write, buffer, lenp, ppos, 27381da177e4SLinus Torvalds do_proc_dointvec_ms_jiffies_conv, NULL); 27391da177e4SLinus Torvalds } 27401da177e4SLinus Torvalds 27418d65af78SAlexey Dobriyan static int proc_do_cad_pid(struct ctl_table *table, int write, 27429ec52099SCedric Le Goater void __user *buffer, size_t *lenp, loff_t *ppos) 27439ec52099SCedric Le Goater { 27449ec52099SCedric Le Goater struct pid *new_pid; 27459ec52099SCedric Le Goater pid_t tmp; 27469ec52099SCedric Le Goater int r; 27479ec52099SCedric Le Goater 27486c5f3e7bSPavel Emelyanov tmp = pid_vnr(cad_pid); 27499ec52099SCedric Le Goater 27508d65af78SAlexey Dobriyan r = __do_proc_dointvec(&tmp, table, write, buffer, 27519ec52099SCedric Le Goater lenp, ppos, NULL, NULL); 27529ec52099SCedric Le Goater if (r || !write) 27539ec52099SCedric Le Goater return r; 27549ec52099SCedric Le Goater 27559ec52099SCedric Le Goater new_pid = find_get_pid(tmp); 27569ec52099SCedric Le Goater if (!new_pid) 27579ec52099SCedric Le Goater return -ESRCH; 27589ec52099SCedric Le Goater 27599ec52099SCedric Le Goater put_pid(xchg(&cad_pid, new_pid)); 27609ec52099SCedric Le Goater return 0; 27619ec52099SCedric Le Goater } 27629ec52099SCedric Le Goater 27639f977fb7SOctavian Purdila /** 27649f977fb7SOctavian Purdila * proc_do_large_bitmap - read/write from/to a large bitmap 27659f977fb7SOctavian Purdila * @table: the sysctl table 27669f977fb7SOctavian Purdila * @write: %TRUE if this is a write to the sysctl file 27679f977fb7SOctavian Purdila * @buffer: the user buffer 27689f977fb7SOctavian Purdila * @lenp: the size of the user buffer 27699f977fb7SOctavian Purdila * @ppos: file position 27709f977fb7SOctavian Purdila * 27719f977fb7SOctavian Purdila * The bitmap is stored at table->data and the bitmap length (in bits) 27729f977fb7SOctavian Purdila * in table->maxlen. 27739f977fb7SOctavian Purdila * 27749f977fb7SOctavian Purdila * We use a range comma separated format (e.g. 1,3-4,10-10) so that 27759f977fb7SOctavian Purdila * large bitmaps may be represented in a compact manner. Writing into 27769f977fb7SOctavian Purdila * the file will clear the bitmap then update it with the given input. 27779f977fb7SOctavian Purdila * 27789f977fb7SOctavian Purdila * Returns 0 on success. 27799f977fb7SOctavian Purdila */ 27809f977fb7SOctavian Purdila int proc_do_large_bitmap(struct ctl_table *table, int write, 27819f977fb7SOctavian Purdila void __user *buffer, size_t *lenp, loff_t *ppos) 27829f977fb7SOctavian Purdila { 27839f977fb7SOctavian Purdila int err = 0; 27849f977fb7SOctavian Purdila bool first = 1; 27859f977fb7SOctavian Purdila size_t left = *lenp; 27869f977fb7SOctavian Purdila unsigned long bitmap_len = table->maxlen; 27879f977fb7SOctavian Purdila unsigned long *bitmap = (unsigned long *) table->data; 27889f977fb7SOctavian Purdila unsigned long *tmp_bitmap = NULL; 27899f977fb7SOctavian Purdila char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c; 27909f977fb7SOctavian Purdila 27919f977fb7SOctavian Purdila if (!bitmap_len || !left || (*ppos && !write)) { 27929f977fb7SOctavian Purdila *lenp = 0; 27939f977fb7SOctavian Purdila return 0; 27949f977fb7SOctavian Purdila } 27959f977fb7SOctavian Purdila 27969f977fb7SOctavian Purdila if (write) { 27979f977fb7SOctavian Purdila unsigned long page = 0; 27989f977fb7SOctavian Purdila char *kbuf; 27999f977fb7SOctavian Purdila 28009f977fb7SOctavian Purdila if (left > PAGE_SIZE - 1) 28019f977fb7SOctavian Purdila left = PAGE_SIZE - 1; 28029f977fb7SOctavian Purdila 28039f977fb7SOctavian Purdila page = __get_free_page(GFP_TEMPORARY); 28049f977fb7SOctavian Purdila kbuf = (char *) page; 28059f977fb7SOctavian Purdila if (!kbuf) 28069f977fb7SOctavian Purdila return -ENOMEM; 28079f977fb7SOctavian Purdila if (copy_from_user(kbuf, buffer, left)) { 28089f977fb7SOctavian Purdila free_page(page); 28099f977fb7SOctavian Purdila return -EFAULT; 28109f977fb7SOctavian Purdila } 28119f977fb7SOctavian Purdila kbuf[left] = 0; 28129f977fb7SOctavian Purdila 28139f977fb7SOctavian Purdila tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long), 28149f977fb7SOctavian Purdila GFP_KERNEL); 28159f977fb7SOctavian Purdila if (!tmp_bitmap) { 28169f977fb7SOctavian Purdila free_page(page); 28179f977fb7SOctavian Purdila return -ENOMEM; 28189f977fb7SOctavian Purdila } 28199f977fb7SOctavian Purdila proc_skip_char(&kbuf, &left, '\n'); 28209f977fb7SOctavian Purdila while (!err && left) { 28219f977fb7SOctavian Purdila unsigned long val_a, val_b; 28229f977fb7SOctavian Purdila bool neg; 28239f977fb7SOctavian Purdila 28249f977fb7SOctavian Purdila err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a, 28259f977fb7SOctavian Purdila sizeof(tr_a), &c); 28269f977fb7SOctavian Purdila if (err) 28279f977fb7SOctavian Purdila break; 28289f977fb7SOctavian Purdila if (val_a >= bitmap_len || neg) { 28299f977fb7SOctavian Purdila err = -EINVAL; 28309f977fb7SOctavian Purdila break; 28319f977fb7SOctavian Purdila } 28329f977fb7SOctavian Purdila 28339f977fb7SOctavian Purdila val_b = val_a; 28349f977fb7SOctavian Purdila if (left) { 28359f977fb7SOctavian Purdila kbuf++; 28369f977fb7SOctavian Purdila left--; 28379f977fb7SOctavian Purdila } 28389f977fb7SOctavian Purdila 28399f977fb7SOctavian Purdila if (c == '-') { 28409f977fb7SOctavian Purdila err = proc_get_long(&kbuf, &left, &val_b, 28419f977fb7SOctavian Purdila &neg, tr_b, sizeof(tr_b), 28429f977fb7SOctavian Purdila &c); 28439f977fb7SOctavian Purdila if (err) 28449f977fb7SOctavian Purdila break; 28459f977fb7SOctavian Purdila if (val_b >= bitmap_len || neg || 28469f977fb7SOctavian Purdila val_a > val_b) { 28479f977fb7SOctavian Purdila err = -EINVAL; 28489f977fb7SOctavian Purdila break; 28499f977fb7SOctavian Purdila } 28509f977fb7SOctavian Purdila if (left) { 28519f977fb7SOctavian Purdila kbuf++; 28529f977fb7SOctavian Purdila left--; 28539f977fb7SOctavian Purdila } 28549f977fb7SOctavian Purdila } 28559f977fb7SOctavian Purdila 28569f977fb7SOctavian Purdila while (val_a <= val_b) 28579f977fb7SOctavian Purdila set_bit(val_a++, tmp_bitmap); 28589f977fb7SOctavian Purdila 28599f977fb7SOctavian Purdila first = 0; 28609f977fb7SOctavian Purdila proc_skip_char(&kbuf, &left, '\n'); 28619f977fb7SOctavian Purdila } 28629f977fb7SOctavian Purdila free_page(page); 28639f977fb7SOctavian Purdila } else { 28649f977fb7SOctavian Purdila unsigned long bit_a, bit_b = 0; 28659f977fb7SOctavian Purdila 28669f977fb7SOctavian Purdila while (left) { 28679f977fb7SOctavian Purdila bit_a = find_next_bit(bitmap, bitmap_len, bit_b); 28689f977fb7SOctavian Purdila if (bit_a >= bitmap_len) 28699f977fb7SOctavian Purdila break; 28709f977fb7SOctavian Purdila bit_b = find_next_zero_bit(bitmap, bitmap_len, 28719f977fb7SOctavian Purdila bit_a + 1) - 1; 28729f977fb7SOctavian Purdila 28739f977fb7SOctavian Purdila if (!first) { 28749f977fb7SOctavian Purdila err = proc_put_char(&buffer, &left, ','); 28759f977fb7SOctavian Purdila if (err) 28769f977fb7SOctavian Purdila break; 28779f977fb7SOctavian Purdila } 28789f977fb7SOctavian Purdila err = proc_put_long(&buffer, &left, bit_a, false); 28799f977fb7SOctavian Purdila if (err) 28809f977fb7SOctavian Purdila break; 28819f977fb7SOctavian Purdila if (bit_a != bit_b) { 28829f977fb7SOctavian Purdila err = proc_put_char(&buffer, &left, '-'); 28839f977fb7SOctavian Purdila if (err) 28849f977fb7SOctavian Purdila break; 28859f977fb7SOctavian Purdila err = proc_put_long(&buffer, &left, bit_b, false); 28869f977fb7SOctavian Purdila if (err) 28879f977fb7SOctavian Purdila break; 28889f977fb7SOctavian Purdila } 28899f977fb7SOctavian Purdila 28909f977fb7SOctavian Purdila first = 0; bit_b++; 28919f977fb7SOctavian Purdila } 28929f977fb7SOctavian Purdila if (!err) 28939f977fb7SOctavian Purdila err = proc_put_char(&buffer, &left, '\n'); 28949f977fb7SOctavian Purdila } 28959f977fb7SOctavian Purdila 28969f977fb7SOctavian Purdila if (!err) { 28979f977fb7SOctavian Purdila if (write) { 28989f977fb7SOctavian Purdila if (*ppos) 28999f977fb7SOctavian Purdila bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len); 29009f977fb7SOctavian Purdila else 29019f977fb7SOctavian Purdila memcpy(bitmap, tmp_bitmap, 29029f977fb7SOctavian Purdila BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long)); 29039f977fb7SOctavian Purdila } 29049f977fb7SOctavian Purdila kfree(tmp_bitmap); 29059f977fb7SOctavian Purdila *lenp -= left; 29069f977fb7SOctavian Purdila *ppos += *lenp; 29079f977fb7SOctavian Purdila return 0; 29089f977fb7SOctavian Purdila } else { 29099f977fb7SOctavian Purdila kfree(tmp_bitmap); 29109f977fb7SOctavian Purdila return err; 29119f977fb7SOctavian Purdila } 29129f977fb7SOctavian Purdila } 29139f977fb7SOctavian Purdila 291455610500SJovi Zhang #else /* CONFIG_PROC_SYSCTL */ 29151da177e4SLinus Torvalds 29168d65af78SAlexey Dobriyan int proc_dostring(struct ctl_table *table, int write, 29171da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 29181da177e4SLinus Torvalds { 29191da177e4SLinus Torvalds return -ENOSYS; 29201da177e4SLinus Torvalds } 29211da177e4SLinus Torvalds 29228d65af78SAlexey Dobriyan int proc_dointvec(struct ctl_table *table, int write, 29231da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 29241da177e4SLinus Torvalds { 29251da177e4SLinus Torvalds return -ENOSYS; 29261da177e4SLinus Torvalds } 29271da177e4SLinus Torvalds 29288d65af78SAlexey Dobriyan int proc_dointvec_minmax(struct ctl_table *table, int write, 29291da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 29301da177e4SLinus Torvalds { 29311da177e4SLinus Torvalds return -ENOSYS; 29321da177e4SLinus Torvalds } 29331da177e4SLinus Torvalds 29348d65af78SAlexey Dobriyan int proc_dointvec_jiffies(struct ctl_table *table, int write, 29351da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 29361da177e4SLinus Torvalds { 29371da177e4SLinus Torvalds return -ENOSYS; 29381da177e4SLinus Torvalds } 29391da177e4SLinus Torvalds 29408d65af78SAlexey Dobriyan int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, 29411da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 29421da177e4SLinus Torvalds { 29431da177e4SLinus Torvalds return -ENOSYS; 29441da177e4SLinus Torvalds } 29451da177e4SLinus Torvalds 29468d65af78SAlexey Dobriyan int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, 29471da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 29481da177e4SLinus Torvalds { 29491da177e4SLinus Torvalds return -ENOSYS; 29501da177e4SLinus Torvalds } 29511da177e4SLinus Torvalds 29528d65af78SAlexey Dobriyan int proc_doulongvec_minmax(struct ctl_table *table, int write, 29531da177e4SLinus Torvalds void __user *buffer, size_t *lenp, loff_t *ppos) 29541da177e4SLinus Torvalds { 29551da177e4SLinus Torvalds return -ENOSYS; 29561da177e4SLinus Torvalds } 29571da177e4SLinus Torvalds 2958d8217f07SEric W. Biederman int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, 29591da177e4SLinus Torvalds void __user *buffer, 29601da177e4SLinus Torvalds size_t *lenp, loff_t *ppos) 29611da177e4SLinus Torvalds { 29621da177e4SLinus Torvalds return -ENOSYS; 29631da177e4SLinus Torvalds } 29641da177e4SLinus Torvalds 29651da177e4SLinus Torvalds 296655610500SJovi Zhang #endif /* CONFIG_PROC_SYSCTL */ 29671da177e4SLinus Torvalds 29681da177e4SLinus Torvalds /* 29691da177e4SLinus Torvalds * No sense putting this after each symbol definition, twice, 29701da177e4SLinus Torvalds * exception granted :-) 29711da177e4SLinus Torvalds */ 29721da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec); 29731da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies); 29741da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax); 29751da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies); 29761da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies); 29771da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring); 29781da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax); 29791da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); 29801da177e4SLinus Torvalds EXPORT_SYMBOL(register_sysctl_table); 298129e796fdSEric W. Biederman EXPORT_SYMBOL(register_sysctl_paths); 29821da177e4SLinus Torvalds EXPORT_SYMBOL(unregister_sysctl_table); 2983