linux/kernel/sysctl.c
<<
>>
Prefs
   1/*
   2 * sysctl.c: General linux system control interface
   3 *
   4 * Begun 24 March 1995, Stephen Tweedie
   5 * Added /proc support, Dec 1995
   6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
   7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
   8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
   9 * Dynamic registration fixes, Stephen Tweedie.
  10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
  11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
  12 *  Horn.
  13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
  14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
  15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
  16 *  Wendling.
  17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
  18 *  Removed it and replaced it with older style, 03/23/00, Bill Wendling
  19 */
  20
  21#include <linux/module.h>
  22#include <linux/mm.h>
  23#include <linux/swap.h>
  24#include <linux/slab.h>
  25#include <linux/sysctl.h>
  26#include <linux/bitmap.h>
  27#include <linux/signal.h>
  28#include <linux/printk.h>
  29#include <linux/proc_fs.h>
  30#include <linux/security.h>
  31#include <linux/ctype.h>
  32#include <linux/kmemcheck.h>
  33#include <linux/kmemleak.h>
  34#include <linux/fs.h>
  35#include <linux/init.h>
  36#include <linux/kernel.h>
  37#include <linux/kobject.h>
  38#include <linux/net.h>
  39#include <linux/sysrq.h>
  40#include <linux/highuid.h>
  41#include <linux/writeback.h>
  42#include <linux/ratelimit.h>
  43#include <linux/compaction.h>
  44#include <linux/hugetlb.h>
  45#include <linux/initrd.h>
  46#include <linux/key.h>
  47#include <linux/times.h>
  48#include <linux/limits.h>
  49#include <linux/dcache.h>
  50#include <linux/dnotify.h>
  51#include <linux/syscalls.h>
  52#include <linux/vmstat.h>
  53#include <linux/nfs_fs.h>
  54#include <linux/acpi.h>
  55#include <linux/reboot.h>
  56#include <linux/ftrace.h>
  57#include <linux/perf_event.h>
  58#include <linux/kprobes.h>
  59#include <linux/pipe_fs_i.h>
  60#include <linux/oom.h>
  61#include <linux/kmod.h>
  62#include <linux/capability.h>
  63#include <linux/binfmts.h>
  64
  65#include <asm/uaccess.h>
  66#include <asm/processor.h>
  67
  68#ifdef CONFIG_X86
  69#include <asm/nmi.h>
  70#include <asm/stacktrace.h>
  71#include <asm/io.h>
  72#endif
  73#ifdef CONFIG_SPARC
  74#include <asm/setup.h>
  75#endif
  76#ifdef CONFIG_BSD_PROCESS_ACCT
  77#include <linux/acct.h>
  78#endif
  79#ifdef CONFIG_RT_MUTEXES
  80#include <linux/rtmutex.h>
  81#endif
  82#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
  83#include <linux/lockdep.h>
  84#endif
  85#ifdef CONFIG_CHR_DEV_SG
  86#include <scsi/sg.h>
  87#endif
  88
  89#ifdef CONFIG_LOCKUP_DETECTOR
  90#include <linux/nmi.h>
  91#endif
  92
  93
  94#if defined(CONFIG_SYSCTL)
  95
  96/* External variables not in a header file. */
  97extern int sysctl_overcommit_memory;
  98extern int sysctl_overcommit_ratio;
  99extern int max_threads;
 100extern int suid_dumpable;
 101#ifdef CONFIG_COREDUMP
 102extern int core_uses_pid;
 103extern char core_pattern[];
 104extern unsigned int core_pipe_limit;
 105#endif
 106extern int pid_max;
 107extern int min_free_kbytes;
 108extern int pid_max_min, pid_max_max;
 109extern int sysctl_drop_caches;
 110extern int percpu_pagelist_fraction;
 111extern int compat_log;
 112extern int latencytop_enabled;
 113extern int sysctl_nr_open_min, sysctl_nr_open_max;
 114#ifndef CONFIG_MMU
 115extern int sysctl_nr_trim_pages;
 116#endif
 117#ifdef CONFIG_BLOCK
 118extern int blk_iopoll_enabled;
 119#endif
 120
 121/* Constants used for minimum and  maximum */
 122#ifdef CONFIG_LOCKUP_DETECTOR
 123static int sixty = 60;
 124static int neg_one = -1;
 125#endif
 126
 127static int zero;
 128static int __maybe_unused one = 1;
 129static int __maybe_unused two = 2;
 130static int __maybe_unused three = 3;
 131static unsigned long one_ul = 1;
 132static int one_hundred = 100;
 133#ifdef CONFIG_PRINTK
 134static int ten_thousand = 10000;
 135#endif
 136
 137/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
 138static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
 139
 140/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
 141static int maxolduid = 65535;
 142static int minolduid;
 143static int min_percpu_pagelist_fract = 8;
 144
 145static int ngroups_max = NGROUPS_MAX;
 146static const int cap_last_cap = CAP_LAST_CAP;
 147
 148#ifdef CONFIG_INOTIFY_USER
 149#include <linux/inotify.h>
 150#endif
 151#ifdef CONFIG_SPARC
 152#endif
 153
 154#ifdef CONFIG_SPARC64
 155extern int sysctl_tsb_ratio;
 156#endif
 157
 158#ifdef __hppa__
 159extern int pwrsw_enabled;
 160extern int unaligned_enabled;
 161#endif
 162
 163#ifdef CONFIG_IA64
 164extern int no_unaligned_warning;
 165extern int unaligned_dump_stack;
 166#endif
 167
 168#ifdef CONFIG_PROC_SYSCTL
 169static int proc_do_cad_pid(struct ctl_table *table, int write,
 170                  void __user *buffer, size_t *lenp, loff_t *ppos);
 171static int proc_taint(struct ctl_table *table, int write,
 172                               void __user *buffer, size_t *lenp, loff_t *ppos);
 173#endif
 174
 175#ifdef CONFIG_PRINTK
 176static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
 177                                void __user *buffer, size_t *lenp, loff_t *ppos);
 178#endif
 179
 180static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
 181                void __user *buffer, size_t *lenp, loff_t *ppos);
 182#ifdef CONFIG_COREDUMP
 183static int proc_dostring_coredump(struct ctl_table *table, int write,
 184                void __user *buffer, size_t *lenp, loff_t *ppos);
 185#endif
 186
 187#ifdef CONFIG_MAGIC_SYSRQ
 188/* Note: sysrq code uses it's own private copy */
 189static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
 190
 191static int sysrq_sysctl_handler(ctl_table *table, int write,
 192                                void __user *buffer, size_t *lenp,
 193                                loff_t *ppos)
 194{
 195        int error;
 196
 197        error = proc_dointvec(table, write, buffer, lenp, ppos);
 198        if (error)
 199                return error;
 200
 201        if (write)
 202                sysrq_toggle_support(__sysrq_enabled);
 203
 204        return 0;
 205}
 206
 207#endif
 208
 209static struct ctl_table kern_table[];
 210static struct ctl_table vm_table[];
 211static struct ctl_table fs_table[];
 212static struct ctl_table debug_table[];
 213static struct ctl_table dev_table[];
 214extern struct ctl_table random_table[];
 215#ifdef CONFIG_EPOLL
 216extern struct ctl_table epoll_table[];
 217#endif
 218
 219#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
 220int sysctl_legacy_va_layout;
 221#endif
 222
 223/* The default sysctl tables: */
 224
 225static struct ctl_table sysctl_base_table[] = {
 226        {
 227                .procname       = "kernel",
 228                .mode           = 0555,
 229                .child          = kern_table,
 230        },
 231        {
 232                .procname       = "vm",
 233                .mode           = 0555,
 234                .child          = vm_table,
 235        },
 236        {
 237                .procname       = "fs",
 238                .mode           = 0555,
 239                .child          = fs_table,
 240        },
 241        {
 242                .procname       = "debug",
 243                .mode           = 0555,
 244                .child          = debug_table,
 245        },
 246        {
 247                .procname       = "dev",
 248                .mode           = 0555,
 249                .child          = dev_table,
 250        },
 251        { }
 252};
 253
 254#ifdef CONFIG_SCHED_DEBUG
 255static int min_sched_granularity_ns = 100000;           /* 100 usecs */
 256static int max_sched_granularity_ns = NSEC_PER_SEC;     /* 1 second */
 257static int min_wakeup_granularity_ns;                   /* 0 usecs */
 258static int max_wakeup_granularity_ns = NSEC_PER_SEC;    /* 1 second */
 259#ifdef CONFIG_SMP
 260static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
 261static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
 262#endif /* CONFIG_SMP */
 263#endif /* CONFIG_SCHED_DEBUG */
 264
 265#ifdef CONFIG_COMPACTION
 266static int min_extfrag_threshold;
 267static int max_extfrag_threshold = 1000;
 268#endif
 269
 270static struct ctl_table kern_table[] = {
 271        {
 272                .procname       = "sched_child_runs_first",
 273                .data           = &sysctl_sched_child_runs_first,
 274                .maxlen         = sizeof(unsigned int),
 275                .mode           = 0644,
 276                .proc_handler   = proc_dointvec,
 277        },
 278#ifdef CONFIG_SCHED_DEBUG
 279        {
 280                .procname       = "sched_min_granularity_ns",
 281                .data           = &sysctl_sched_min_granularity,
 282                .maxlen         = sizeof(unsigned int),
 283                .mode           = 0644,
 284                .proc_handler   = sched_proc_update_handler,
 285                .extra1         = &min_sched_granularity_ns,
 286                .extra2         = &max_sched_granularity_ns,
 287        },
 288        {
 289                .procname       = "sched_latency_ns",
 290                .data           = &sysctl_sched_latency,
 291                .maxlen         = sizeof(unsigned int),
 292                .mode           = 0644,
 293                .proc_handler   = sched_proc_update_handler,
 294                .extra1         = &min_sched_granularity_ns,
 295                .extra2         = &max_sched_granularity_ns,
 296        },
 297        {
 298                .procname       = "sched_wakeup_granularity_ns",
 299                .data           = &sysctl_sched_wakeup_granularity,
 300                .maxlen         = sizeof(unsigned int),
 301                .mode           = 0644,
 302                .proc_handler   = sched_proc_update_handler,
 303                .extra1         = &min_wakeup_granularity_ns,
 304                .extra2         = &max_wakeup_granularity_ns,
 305        },
 306#ifdef CONFIG_SMP
 307        {
 308                .procname       = "sched_tunable_scaling",
 309                .data           = &sysctl_sched_tunable_scaling,
 310                .maxlen         = sizeof(enum sched_tunable_scaling),
 311                .mode           = 0644,
 312                .proc_handler   = sched_proc_update_handler,
 313                .extra1         = &min_sched_tunable_scaling,
 314                .extra2         = &max_sched_tunable_scaling,
 315        },
 316        {
 317                .procname       = "sched_migration_cost_ns",
 318                .data           = &sysctl_sched_migration_cost,
 319                .maxlen         = sizeof(unsigned int),
 320                .mode           = 0644,
 321                .proc_handler   = proc_dointvec,
 322        },
 323        {
 324                .procname       = "sched_nr_migrate",
 325                .data           = &sysctl_sched_nr_migrate,
 326                .maxlen         = sizeof(unsigned int),
 327                .mode           = 0644,
 328                .proc_handler   = proc_dointvec,
 329        },
 330        {
 331                .procname       = "sched_time_avg_ms",
 332                .data           = &sysctl_sched_time_avg,
 333                .maxlen         = sizeof(unsigned int),
 334                .mode           = 0644,
 335                .proc_handler   = proc_dointvec,
 336        },
 337        {
 338                .procname       = "sched_shares_window_ns",
 339                .data           = &sysctl_sched_shares_window,
 340                .maxlen         = sizeof(unsigned int),
 341                .mode           = 0644,
 342                .proc_handler   = proc_dointvec,
 343        },
 344        {
 345                .procname       = "timer_migration",
 346                .data           = &sysctl_timer_migration,
 347                .maxlen         = sizeof(unsigned int),
 348                .mode           = 0644,
 349                .proc_handler   = proc_dointvec_minmax,
 350                .extra1         = &zero,
 351                .extra2         = &one,
 352        },
 353#endif /* CONFIG_SMP */
 354#ifdef CONFIG_NUMA_BALANCING
 355        {
 356                .procname       = "numa_balancing_scan_delay_ms",
 357                .data           = &sysctl_numa_balancing_scan_delay,
 358                .maxlen         = sizeof(unsigned int),
 359                .mode           = 0644,
 360                .proc_handler   = proc_dointvec,
 361        },
 362        {
 363                .procname       = "numa_balancing_scan_period_min_ms",
 364                .data           = &sysctl_numa_balancing_scan_period_min,
 365                .maxlen         = sizeof(unsigned int),
 366                .mode           = 0644,
 367                .proc_handler   = proc_dointvec,
 368        },
 369        {
 370                .procname       = "numa_balancing_scan_period_reset",
 371                .data           = &sysctl_numa_balancing_scan_period_reset,
 372                .maxlen         = sizeof(unsigned int),
 373                .mode           = 0644,
 374                .proc_handler   = proc_dointvec,
 375        },
 376        {
 377                .procname       = "numa_balancing_scan_period_max_ms",
 378                .data           = &sysctl_numa_balancing_scan_period_max,
 379                .maxlen         = sizeof(unsigned int),
 380                .mode           = 0644,
 381                .proc_handler   = proc_dointvec,
 382        },
 383        {
 384                .procname       = "numa_balancing_scan_size_mb",
 385                .data           = &sysctl_numa_balancing_scan_size,
 386                .maxlen         = sizeof(unsigned int),
 387                .mode           = 0644,
 388                .proc_handler   = proc_dointvec,
 389        },
 390#endif /* CONFIG_NUMA_BALANCING */
 391#endif /* CONFIG_SCHED_DEBUG */
 392        {
 393                .procname       = "sched_rt_period_us",
 394                .data           = &sysctl_sched_rt_period,
 395                .maxlen         = sizeof(unsigned int),
 396                .mode           = 0644,
 397                .proc_handler   = sched_rt_handler,
 398        },
 399        {
 400                .procname       = "sched_rt_runtime_us",
 401                .data           = &sysctl_sched_rt_runtime,
 402                .maxlen         = sizeof(int),
 403                .mode           = 0644,
 404                .proc_handler   = sched_rt_handler,
 405        },
 406#ifdef CONFIG_SCHED_AUTOGROUP
 407        {
 408                .procname       = "sched_autogroup_enabled",
 409                .data           = &sysctl_sched_autogroup_enabled,
 410                .maxlen         = sizeof(unsigned int),
 411                .mode           = 0644,
 412                .proc_handler   = proc_dointvec_minmax,
 413                .extra1         = &zero,
 414                .extra2         = &one,
 415        },
 416#endif
 417#ifdef CONFIG_CFS_BANDWIDTH
 418        {
 419                .procname       = "sched_cfs_bandwidth_slice_us",
 420                .data           = &sysctl_sched_cfs_bandwidth_slice,
 421                .maxlen         = sizeof(unsigned int),
 422                .mode           = 0644,
 423                .proc_handler   = proc_dointvec_minmax,
 424                .extra1         = &one,
 425        },
 426#endif
 427#ifdef CONFIG_PROVE_LOCKING
 428        {
 429                .procname       = "prove_locking",
 430                .data           = &prove_locking,
 431                .maxlen         = sizeof(int),
 432                .mode           = 0644,
 433                .proc_handler   = proc_dointvec,
 434        },
 435#endif
 436#ifdef CONFIG_LOCK_STAT
 437        {
 438                .procname       = "lock_stat",
 439                .data           = &lock_stat,
 440                .maxlen         = sizeof(int),
 441                .mode           = 0644,
 442                .proc_handler   = proc_dointvec,
 443        },
 444#endif
 445        {
 446                .procname       = "panic",
 447                .data           = &panic_timeout,
 448                .maxlen         = sizeof(int),
 449                .mode           = 0644,
 450                .proc_handler   = proc_dointvec,
 451        },
 452#ifdef CONFIG_COREDUMP
 453        {
 454                .procname       = "core_uses_pid",
 455                .data           = &core_uses_pid,
 456                .maxlen         = sizeof(int),
 457                .mode           = 0644,
 458                .proc_handler   = proc_dointvec,
 459        },
 460        {
 461                .procname       = "core_pattern",
 462                .data           = core_pattern,
 463                .maxlen         = CORENAME_MAX_SIZE,
 464                .mode           = 0644,
 465                .proc_handler   = proc_dostring_coredump,
 466        },
 467        {
 468                .procname       = "core_pipe_limit",
 469                .data           = &core_pipe_limit,
 470                .maxlen         = sizeof(unsigned int),
 471                .mode           = 0644,
 472                .proc_handler   = proc_dointvec,
 473        },
 474#endif
 475#ifdef CONFIG_PROC_SYSCTL
 476        {
 477                .procname       = "tainted",
 478                .maxlen         = sizeof(long),
 479                .mode           = 0644,
 480                .proc_handler   = proc_taint,
 481        },
 482#endif
 483#ifdef CONFIG_LATENCYTOP
 484        {
 485                .procname       = "latencytop",
 486                .data           = &latencytop_enabled,
 487                .maxlen         = sizeof(int),
 488                .mode           = 0644,
 489                .proc_handler   = proc_dointvec,
 490        },
 491#endif
 492#ifdef CONFIG_BLK_DEV_INITRD
 493        {
 494                .procname       = "real-root-dev",
 495                .data           = &real_root_dev,
 496                .maxlen         = sizeof(int),
 497                .mode           = 0644,
 498                .proc_handler   = proc_dointvec,
 499        },
 500#endif
 501        {
 502                .procname       = "print-fatal-signals",
 503                .data           = &print_fatal_signals,
 504                .maxlen         = sizeof(int),
 505                .mode           = 0644,
 506                .proc_handler   = proc_dointvec,
 507        },
 508#ifdef CONFIG_SPARC
 509        {
 510                .procname       = "reboot-cmd",
 511                .data           = reboot_command,
 512                .maxlen         = 256,
 513                .mode           = 0644,
 514                .proc_handler   = proc_dostring,
 515        },
 516        {
 517                .procname       = "stop-a",
 518                .data           = &stop_a_enabled,
 519                .maxlen         = sizeof (int),
 520                .mode           = 0644,
 521                .proc_handler   = proc_dointvec,
 522        },
 523        {
 524                .procname       = "scons-poweroff",
 525                .data           = &scons_pwroff,
 526                .maxlen         = sizeof (int),
 527                .mode           = 0644,
 528                .proc_handler   = proc_dointvec,
 529        },
 530#endif
 531#ifdef CONFIG_SPARC64
 532        {
 533                .procname       = "tsb-ratio",
 534                .data           = &sysctl_tsb_ratio,
 535                .maxlen         = sizeof (int),
 536                .mode           = 0644,
 537                .proc_handler   = proc_dointvec,
 538        },
 539#endif
 540#ifdef __hppa__
 541        {
 542                .procname       = "soft-power",
 543                .data           = &pwrsw_enabled,
 544                .maxlen         = sizeof (int),
 545                .mode           = 0644,
 546                .proc_handler   = proc_dointvec,
 547        },
 548        {
 549                .procname       = "unaligned-trap",
 550                .data           = &unaligned_enabled,
 551                .maxlen         = sizeof (int),
 552                .mode           = 0644,
 553                .proc_handler   = proc_dointvec,
 554        },
 555#endif
 556        {
 557                .procname       = "ctrl-alt-del",
 558                .data           = &C_A_D,
 559                .maxlen         = sizeof(int),
 560                .mode           = 0644,
 561                .proc_handler   = proc_dointvec,
 562        },
 563#ifdef CONFIG_FUNCTION_TRACER
 564        {
 565                .procname       = "ftrace_enabled",
 566                .data           = &ftrace_enabled,
 567                .maxlen         = sizeof(int),
 568                .mode           = 0644,
 569                .proc_handler   = ftrace_enable_sysctl,
 570        },
 571#endif
 572#ifdef CONFIG_STACK_TRACER
 573        {
 574                .procname       = "stack_tracer_enabled",
 575                .data           = &stack_tracer_enabled,
 576                .maxlen         = sizeof(int),
 577                .mode           = 0644,
 578                .proc_handler   = stack_trace_sysctl,
 579        },
 580#endif
 581#ifdef CONFIG_TRACING
 582        {
 583                .procname       = "ftrace_dump_on_oops",
 584                .data           = &ftrace_dump_on_oops,
 585                .maxlen         = sizeof(int),
 586                .mode           = 0644,
 587                .proc_handler   = proc_dointvec,
 588        },
 589#endif
 590#ifdef CONFIG_MODULES
 591        {
 592                .procname       = "modprobe",
 593                .data           = &modprobe_path,
 594                .maxlen         = KMOD_PATH_LEN,
 595                .mode           = 0644,
 596                .proc_handler   = proc_dostring,
 597        },
 598        {
 599                .procname       = "modules_disabled",
 600                .data           = &modules_disabled,
 601                .maxlen         = sizeof(int),
 602                .mode           = 0644,
 603                /* only handle a transition from default "0" to "1" */
 604                .proc_handler   = proc_dointvec_minmax,
 605                .extra1         = &one,
 606                .extra2         = &one,
 607        },
 608#endif
 609
 610        {
 611                .procname       = "hotplug",
 612                .data           = &uevent_helper,
 613                .maxlen         = UEVENT_HELPER_PATH_LEN,
 614                .mode           = 0644,
 615                .proc_handler   = proc_dostring,
 616        },
 617
 618#ifdef CONFIG_CHR_DEV_SG
 619        {
 620                .procname       = "sg-big-buff",
 621                .data           = &sg_big_buff,
 622                .maxlen         = sizeof (int),
 623                .mode           = 0444,
 624                .proc_handler   = proc_dointvec,
 625        },
 626#endif
 627#ifdef CONFIG_BSD_PROCESS_ACCT
 628        {
 629                .procname       = "acct",
 630                .data           = &acct_parm,
 631                .maxlen         = 3*sizeof(int),
 632                .mode           = 0644,
 633                .proc_handler   = proc_dointvec,
 634        },
 635#endif
 636#ifdef CONFIG_MAGIC_SYSRQ
 637        {
 638                .procname       = "sysrq",
 639                .data           = &__sysrq_enabled,
 640                .maxlen         = sizeof (int),
 641                .mode           = 0644,
 642                .proc_handler   = sysrq_sysctl_handler,
 643        },
 644#endif
 645#ifdef CONFIG_PROC_SYSCTL
 646        {
 647                .procname       = "cad_pid",
 648                .data           = NULL,
 649                .maxlen         = sizeof (int),
 650                .mode           = 0600,
 651                .proc_handler   = proc_do_cad_pid,
 652        },
 653#endif
 654        {
 655                .procname       = "threads-max",
 656                .data           = &max_threads,
 657                .maxlen         = sizeof(int),
 658                .mode           = 0644,
 659                .proc_handler   = proc_dointvec,
 660        },
 661        {
 662                .procname       = "random",
 663                .mode           = 0555,
 664                .child          = random_table,
 665        },
 666        {
 667                .procname       = "usermodehelper",
 668                .mode           = 0555,
 669                .child          = usermodehelper_table,
 670        },
 671        {
 672                .procname       = "overflowuid",
 673                .data           = &overflowuid,
 674                .maxlen         = sizeof(int),
 675                .mode           = 0644,
 676                .proc_handler   = proc_dointvec_minmax,
 677                .extra1         = &minolduid,
 678                .extra2         = &maxolduid,
 679        },
 680        {
 681                .procname       = "overflowgid",
 682                .data           = &overflowgid,
 683                .maxlen         = sizeof(int),
 684                .mode           = 0644,
 685                .proc_handler   = proc_dointvec_minmax,
 686                .extra1         = &minolduid,
 687                .extra2         = &maxolduid,
 688        },
 689#ifdef CONFIG_S390
 690#ifdef CONFIG_MATHEMU
 691        {
 692                .procname       = "ieee_emulation_warnings",
 693                .data           = &sysctl_ieee_emulation_warnings,
 694                .maxlen         = sizeof(int),
 695                .mode           = 0644,
 696                .proc_handler   = proc_dointvec,
 697        },
 698#endif
 699        {
 700                .procname       = "userprocess_debug",
 701                .data           = &show_unhandled_signals,
 702                .maxlen         = sizeof(int),
 703                .mode           = 0644,
 704                .proc_handler   = proc_dointvec,
 705        },
 706#endif
 707        {
 708                .procname       = "pid_max",
 709                .data           = &pid_max,
 710                .maxlen         = sizeof (int),
 711                .mode           = 0644,
 712                .proc_handler   = proc_dointvec_minmax,
 713                .extra1         = &pid_max_min,
 714                .extra2         = &pid_max_max,
 715        },
 716        {
 717                .procname       = "panic_on_oops",
 718                .data           = &panic_on_oops,
 719                .maxlen         = sizeof(int),
 720                .mode           = 0644,
 721                .proc_handler   = proc_dointvec,
 722        },
 723#if defined CONFIG_PRINTK
 724        {
 725                .procname       = "printk",
 726                .data           = &console_loglevel,
 727                .maxlen         = 4*sizeof(int),
 728                .mode           = 0644,
 729                .proc_handler   = proc_dointvec,
 730        },
 731        {
 732                .procname       = "printk_ratelimit",
 733                .data           = &printk_ratelimit_state.interval,
 734                .maxlen         = sizeof(int),
 735                .mode           = 0644,
 736                .proc_handler   = proc_dointvec_jiffies,
 737        },
 738        {
 739                .procname       = "printk_ratelimit_burst",
 740                .data           = &printk_ratelimit_state.burst,
 741                .maxlen         = sizeof(int),
 742                .mode           = 0644,
 743                .proc_handler   = proc_dointvec,
 744        },
 745        {
 746                .procname       = "printk_delay",
 747                .data           = &printk_delay_msec,
 748                .maxlen         = sizeof(int),
 749                .mode           = 0644,
 750                .proc_handler   = proc_dointvec_minmax,
 751                .extra1         = &zero,
 752                .extra2         = &ten_thousand,
 753        },
 754        {
 755                .procname       = "dmesg_restrict",
 756                .data           = &dmesg_restrict,
 757                .maxlen         = sizeof(int),
 758                .mode           = 0644,
 759                .proc_handler   = proc_dointvec_minmax_sysadmin,
 760                .extra1         = &zero,
 761                .extra2         = &one,
 762        },
 763        {
 764                .procname       = "kptr_restrict",
 765                .data           = &kptr_restrict,
 766                .maxlen         = sizeof(int),
 767                .mode           = 0644,
 768                .proc_handler   = proc_dointvec_minmax_sysadmin,
 769                .extra1         = &zero,
 770                .extra2         = &two,
 771        },
 772#endif
 773        {
 774                .procname       = "ngroups_max",
 775                .data           = &ngroups_max,
 776                .maxlen         = sizeof (int),
 777                .mode           = 0444,
 778                .proc_handler   = proc_dointvec,
 779        },
 780        {
 781                .procname       = "cap_last_cap",
 782                .data           = (void *)&cap_last_cap,
 783                .maxlen         = sizeof(int),
 784                .mode           = 0444,
 785                .proc_handler   = proc_dointvec,
 786        },
 787#if defined(CONFIG_LOCKUP_DETECTOR)
 788        {
 789                .procname       = "watchdog",
 790                .data           = &watchdog_enabled,
 791                .maxlen         = sizeof (int),
 792                .mode           = 0644,
 793                .proc_handler   = proc_dowatchdog,
 794                .extra1         = &zero,
 795                .extra2         = &one,
 796        },
 797        {
 798                .procname       = "watchdog_thresh",
 799                .data           = &watchdog_thresh,
 800                .maxlen         = sizeof(int),
 801                .mode           = 0644,
 802                .proc_handler   = proc_dowatchdog,
 803                .extra1         = &neg_one,
 804                .extra2         = &sixty,
 805        },
 806        {
 807                .procname       = "softlockup_panic",
 808                .data           = &softlockup_panic,
 809                .maxlen         = sizeof(int),
 810                .mode           = 0644,
 811                .proc_handler   = proc_dointvec_minmax,
 812                .extra1         = &zero,
 813                .extra2         = &one,
 814        },
 815        {
 816                .procname       = "nmi_watchdog",
 817                .data           = &watchdog_enabled,
 818                .maxlen         = sizeof (int),
 819                .mode           = 0644,
 820                .proc_handler   = proc_dowatchdog,
 821                .extra1         = &zero,
 822                .extra2         = &one,
 823        },
 824#endif
 825#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
 826        {
 827                .procname       = "unknown_nmi_panic",
 828                .data           = &unknown_nmi_panic,
 829                .maxlen         = sizeof (int),
 830                .mode           = 0644,
 831                .proc_handler   = proc_dointvec,
 832        },
 833#endif
 834#if defined(CONFIG_X86)
 835        {
 836                .procname       = "panic_on_unrecovered_nmi",
 837                .data           = &panic_on_unrecovered_nmi,
 838                .maxlen         = sizeof(int),
 839                .mode           = 0644,
 840                .proc_handler   = proc_dointvec,
 841        },
 842        {
 843                .procname       = "panic_on_io_nmi",
 844                .data           = &panic_on_io_nmi,
 845                .maxlen         = sizeof(int),
 846                .mode           = 0644,
 847                .proc_handler   = proc_dointvec,
 848        },
 849#ifdef CONFIG_DEBUG_STACKOVERFLOW
 850        {
 851                .procname       = "panic_on_stackoverflow",
 852                .data           = &sysctl_panic_on_stackoverflow,
 853                .maxlen         = sizeof(int),
 854                .mode           = 0644,
 855                .proc_handler   = proc_dointvec,
 856        },
 857#endif
 858        {
 859                .procname       = "bootloader_type",
 860                .data           = &bootloader_type,
 861                .maxlen         = sizeof (int),
 862                .mode           = 0444,
 863                .proc_handler   = proc_dointvec,
 864        },
 865        {
 866                .procname       = "bootloader_version",
 867                .data           = &bootloader_version,
 868                .maxlen         = sizeof (int),
 869                .mode           = 0444,
 870                .proc_handler   = proc_dointvec,
 871        },
 872        {
 873                .procname       = "kstack_depth_to_print",
 874                .data           = &kstack_depth_to_print,
 875                .maxlen         = sizeof(int),
 876                .mode           = 0644,
 877                .proc_handler   = proc_dointvec,
 878        },
 879        {
 880                .procname       = "io_delay_type",
 881                .data           = &io_delay_type,
 882                .maxlen         = sizeof(int),
 883                .mode           = 0644,
 884                .proc_handler   = proc_dointvec,
 885        },
 886#endif
 887#if defined(CONFIG_MMU)
 888        {
 889                .procname       = "randomize_va_space",
 890                .data           = &randomize_va_space,
 891                .maxlen         = sizeof(int),
 892                .mode           = 0644,
 893                .proc_handler   = proc_dointvec,
 894        },
 895#endif
 896#if defined(CONFIG_S390) && defined(CONFIG_SMP)
 897        {
 898                .procname       = "spin_retry",
 899                .data           = &spin_retry,
 900                .maxlen         = sizeof (int),
 901                .mode           = 0644,
 902                .proc_handler   = proc_dointvec,
 903        },
 904#endif
 905#if     defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
 906        {
 907                .procname       = "acpi_video_flags",
 908                .data           = &acpi_realmode_flags,
 909                .maxlen         = sizeof (unsigned long),
 910                .mode           = 0644,
 911                .proc_handler   = proc_doulongvec_minmax,
 912        },
 913#endif
 914#ifdef CONFIG_IA64
 915        {
 916                .procname       = "ignore-unaligned-usertrap",
 917                .data           = &no_unaligned_warning,
 918                .maxlen         = sizeof (int),
 919                .mode           = 0644,
 920                .proc_handler   = proc_dointvec,
 921        },
 922        {
 923                .procname       = "unaligned-dump-stack",
 924                .data           = &unaligned_dump_stack,
 925                .maxlen         = sizeof (int),
 926                .mode           = 0644,
 927                .proc_handler   = proc_dointvec,
 928        },
 929#endif
 930#ifdef CONFIG_DETECT_HUNG_TASK
 931        {
 932                .procname       = "hung_task_panic",
 933                .data           = &sysctl_hung_task_panic,
 934                .maxlen         = sizeof(int),
 935                .mode           = 0644,
 936                .proc_handler   = proc_dointvec_minmax,
 937                .extra1         = &zero,
 938                .extra2         = &one,
 939        },
 940        {
 941                .procname       = "hung_task_check_count",
 942                .data           = &sysctl_hung_task_check_count,
 943                .maxlen         = sizeof(unsigned long),
 944                .mode           = 0644,
 945                .proc_handler   = proc_doulongvec_minmax,
 946        },
 947        {
 948                .procname       = "hung_task_timeout_secs",
 949                .data           = &sysctl_hung_task_timeout_secs,
 950                .maxlen         = sizeof(unsigned long),
 951                .mode           = 0644,
 952                .proc_handler   = proc_dohung_task_timeout_secs,
 953        },
 954        {
 955                .procname       = "hung_task_warnings",
 956                .data           = &sysctl_hung_task_warnings,
 957                .maxlen         = sizeof(unsigned long),
 958                .mode           = 0644,
 959                .proc_handler   = proc_doulongvec_minmax,
 960        },
 961#endif
 962#ifdef CONFIG_COMPAT
 963        {
 964                .procname       = "compat-log",
 965                .data           = &compat_log,
 966                .maxlen         = sizeof (int),
 967                .mode           = 0644,
 968                .proc_handler   = proc_dointvec,
 969        },
 970#endif
 971#ifdef CONFIG_RT_MUTEXES
 972        {
 973                .procname       = "max_lock_depth",
 974                .data           = &max_lock_depth,
 975                .maxlen         = sizeof(int),
 976                .mode           = 0644,
 977                .proc_handler   = proc_dointvec,
 978        },
 979#endif
 980        {
 981                .procname       = "poweroff_cmd",
 982                .data           = &poweroff_cmd,
 983                .maxlen         = POWEROFF_CMD_PATH_LEN,
 984                .mode           = 0644,
 985                .proc_handler   = proc_dostring,
 986        },
 987#ifdef CONFIG_KEYS
 988        {
 989                .procname       = "keys",
 990                .mode           = 0555,
 991                .child          = key_sysctls,
 992        },
 993#endif
 994#ifdef CONFIG_RCU_TORTURE_TEST
 995        {
 996                .procname       = "rcutorture_runnable",
 997                .data           = &rcutorture_runnable,
 998                .maxlen         = sizeof(int),
 999                .mode           = 0644,
1000                .proc_handler   = proc_dointvec,
1001        },
1002#endif
1003#ifdef CONFIG_PERF_EVENTS
1004        /*
1005         * User-space scripts rely on the existence of this file
1006         * as a feature check for perf_events being enabled.
1007         *
1008         * So it's an ABI, do not remove!
1009         */
1010        {
1011                .procname       = "perf_event_paranoid",
1012                .data           = &sysctl_perf_event_paranoid,
1013                .maxlen         = sizeof(sysctl_perf_event_paranoid),
1014                .mode           = 0644,
1015                .proc_handler   = proc_dointvec,
1016        },
1017        {
1018                .procname       = "perf_event_mlock_kb",
1019                .data           = &sysctl_perf_event_mlock,
1020                .maxlen         = sizeof(sysctl_perf_event_mlock),
1021                .mode           = 0644,
1022                .proc_handler   = proc_dointvec,
1023        },
1024        {
1025                .procname       = "perf_event_max_sample_rate",
1026                .data           = &sysctl_perf_event_sample_rate,
1027                .maxlen         = sizeof(sysctl_perf_event_sample_rate),
1028                .mode           = 0644,
1029                .proc_handler   = perf_proc_update_handler,
1030        },
1031#endif
1032#ifdef CONFIG_KMEMCHECK
1033        {
1034                .procname       = "kmemcheck",
1035                .data           = &kmemcheck_enabled,
1036                .maxlen         = sizeof(int),
1037                .mode           = 0644,
1038                .proc_handler   = proc_dointvec,
1039        },
1040#endif
1041#ifdef CONFIG_BLOCK
1042        {
1043                .procname       = "blk_iopoll",
1044                .data           = &blk_iopoll_enabled,
1045                .maxlen         = sizeof(int),
1046                .mode           = 0644,
1047                .proc_handler   = proc_dointvec,
1048        },
1049#endif
1050        { }
1051};
1052
1053static struct ctl_table vm_table[] = {
1054        {
1055                .procname       = "overcommit_memory",
1056                .data           = &sysctl_overcommit_memory,
1057                .maxlen         = sizeof(sysctl_overcommit_memory),
1058                .mode           = 0644,
1059                .proc_handler   = proc_dointvec_minmax,
1060                .extra1         = &zero,
1061                .extra2         = &two,
1062        },
1063        {
1064                .procname       = "panic_on_oom",
1065                .data           = &sysctl_panic_on_oom,
1066                .maxlen         = sizeof(sysctl_panic_on_oom),
1067                .mode           = 0644,
1068                .proc_handler   = proc_dointvec_minmax,
1069                .extra1         = &zero,
1070                .extra2         = &two,
1071        },
1072        {
1073                .procname       = "oom_kill_allocating_task",
1074                .data           = &sysctl_oom_kill_allocating_task,
1075                .maxlen         = sizeof(sysctl_oom_kill_allocating_task),
1076                .mode           = 0644,
1077                .proc_handler   = proc_dointvec,
1078        },
1079        {
1080                .procname       = "oom_dump_tasks",
1081                .data           = &sysctl_oom_dump_tasks,
1082                .maxlen         = sizeof(sysctl_oom_dump_tasks),
1083                .mode           = 0644,
1084                .proc_handler   = proc_dointvec,
1085        },
1086        {
1087                .procname       = "overcommit_ratio",
1088                .data           = &sysctl_overcommit_ratio,
1089                .maxlen         = sizeof(sysctl_overcommit_ratio),
1090                .mode           = 0644,
1091                .proc_handler   = proc_dointvec,
1092        },
1093        {
1094                .procname       = "page-cluster", 
1095                .data           = &page_cluster,
1096                .maxlen         = sizeof(int),
1097                .mode           = 0644,
1098                .proc_handler   = proc_dointvec_minmax,
1099                .extra1         = &zero,
1100        },
1101        {
1102                .procname       = "dirty_background_ratio",
1103                .data           = &dirty_background_ratio,
1104                .maxlen         = sizeof(dirty_background_ratio),
1105                .mode           = 0644,
1106                .proc_handler   = dirty_background_ratio_handler,
1107                .extra1         = &zero,
1108                .extra2         = &one_hundred,
1109        },
1110        {
1111                .procname       = "dirty_background_bytes",
1112                .data           = &dirty_background_bytes,
1113                .maxlen         = sizeof(dirty_background_bytes),
1114                .mode           = 0644,
1115                .proc_handler   = dirty_background_bytes_handler,
1116                .extra1         = &one_ul,
1117        },
1118        {
1119                .procname       = "dirty_ratio",
1120                .data           = &vm_dirty_ratio,
1121                .maxlen         = sizeof(vm_dirty_ratio),
1122                .mode           = 0644,
1123                .proc_handler   = dirty_ratio_handler,
1124                .extra1         = &zero,
1125                .extra2         = &one_hundred,
1126        },
1127        {
1128                .procname       = "dirty_bytes",
1129                .data           = &vm_dirty_bytes,
1130                .maxlen         = sizeof(vm_dirty_bytes),
1131                .mode           = 0644,
1132                .proc_handler   = dirty_bytes_handler,
1133                .extra1         = &dirty_bytes_min,
1134        },
1135        {
1136                .procname       = "dirty_writeback_centisecs",
1137                .data           = &dirty_writeback_interval,
1138                .maxlen         = sizeof(dirty_writeback_interval),
1139                .mode           = 0644,
1140                .proc_handler   = dirty_writeback_centisecs_handler,
1141        },
1142        {
1143                .procname       = "dirty_expire_centisecs",
1144                .data           = &dirty_expire_interval,
1145                .maxlen         = sizeof(dirty_expire_interval),
1146                .mode           = 0644,
1147                .proc_handler   = proc_dointvec_minmax,
1148                .extra1         = &zero,
1149        },
1150        {
1151                .procname       = "nr_pdflush_threads",
1152                .mode           = 0444 /* read-only */,
1153                .proc_handler   = pdflush_proc_obsolete,
1154        },
1155        {
1156                .procname       = "swappiness",
1157                .data           = &vm_swappiness,
1158                .maxlen         = sizeof(vm_swappiness),
1159                .mode           = 0644,
1160                .proc_handler   = proc_dointvec_minmax,
1161                .extra1         = &zero,
1162                .extra2         = &one_hundred,
1163        },
1164#ifdef CONFIG_HUGETLB_PAGE
1165        {
1166                .procname       = "nr_hugepages",
1167                .data           = NULL,
1168                .maxlen         = sizeof(unsigned long),
1169                .mode           = 0644,
1170                .proc_handler   = hugetlb_sysctl_handler,
1171                .extra1         = (void *)&hugetlb_zero,
1172                .extra2         = (void *)&hugetlb_infinity,
1173        },
1174#ifdef CONFIG_NUMA
1175        {
1176                .procname       = "nr_hugepages_mempolicy",
1177                .data           = NULL,
1178                .maxlen         = sizeof(unsigned long),
1179                .mode           = 0644,
1180                .proc_handler   = &hugetlb_mempolicy_sysctl_handler,
1181                .extra1         = (void *)&hugetlb_zero,
1182                .extra2         = (void *)&hugetlb_infinity,
1183        },
1184#endif
1185         {
1186                .procname       = "hugetlb_shm_group",
1187                .data           = &sysctl_hugetlb_shm_group,
1188                .maxlen         = sizeof(gid_t),
1189                .mode           = 0644,
1190                .proc_handler   = proc_dointvec,
1191         },
1192         {
1193                .procname       = "hugepages_treat_as_movable",
1194                .data           = &hugepages_treat_as_movable,
1195                .maxlen         = sizeof(int),
1196                .mode           = 0644,
1197                .proc_handler   = hugetlb_treat_movable_handler,
1198        },
1199        {
1200                .procname       = "nr_overcommit_hugepages",
1201                .data           = NULL,
1202                .maxlen         = sizeof(unsigned long),
1203                .mode           = 0644,
1204                .proc_handler   = hugetlb_overcommit_handler,
1205                .extra1         = (void *)&hugetlb_zero,
1206                .extra2         = (void *)&hugetlb_infinity,
1207        },
1208#endif
1209        {
1210                .procname       = "lowmem_reserve_ratio",
1211                .data           = &sysctl_lowmem_reserve_ratio,
1212                .maxlen         = sizeof(sysctl_lowmem_reserve_ratio),
1213                .mode           = 0644,
1214                .proc_handler   = lowmem_reserve_ratio_sysctl_handler,
1215        },
1216        {
1217                .procname       = "drop_caches",
1218                .data           = &sysctl_drop_caches,
1219                .maxlen         = sizeof(int),
1220                .mode           = 0644,
1221                .proc_handler   = drop_caches_sysctl_handler,
1222                .extra1         = &one,
1223                .extra2         = &three,
1224        },
1225#ifdef CONFIG_COMPACTION
1226        {
1227                .procname       = "compact_memory",
1228                .data           = &sysctl_compact_memory,
1229                .maxlen         = sizeof(int),
1230                .mode           = 0200,
1231                .proc_handler   = sysctl_compaction_handler,
1232        },
1233        {
1234                .procname       = "extfrag_threshold",
1235                .data           = &sysctl_extfrag_threshold,
1236                .maxlen         = sizeof(int),
1237                .mode           = 0644,
1238                .proc_handler   = sysctl_extfrag_handler,
1239                .extra1         = &min_extfrag_threshold,
1240                .extra2         = &max_extfrag_threshold,
1241        },
1242
1243#endif /* CONFIG_COMPACTION */
1244        {
1245                .procname       = "min_free_kbytes",
1246                .data           = &min_free_kbytes,
1247                .maxlen         = sizeof(min_free_kbytes),
1248                .mode           = 0644,
1249                .proc_handler   = min_free_kbytes_sysctl_handler,
1250                .extra1         = &zero,
1251        },
1252        {
1253                .procname       = "percpu_pagelist_fraction",
1254                .data           = &percpu_pagelist_fraction,
1255                .maxlen         = sizeof(percpu_pagelist_fraction),
1256                .mode           = 0644,
1257                .proc_handler   = percpu_pagelist_fraction_sysctl_handler,
1258                .extra1         = &min_percpu_pagelist_fract,
1259        },
1260#ifdef CONFIG_MMU
1261        {
1262                .procname       = "max_map_count",
1263                .data           = &sysctl_max_map_count,
1264                .maxlen         = sizeof(sysctl_max_map_count),
1265                .mode           = 0644,
1266                .proc_handler   = proc_dointvec_minmax,
1267                .extra1         = &zero,
1268        },
1269#else
1270        {
1271                .procname       = "nr_trim_pages",
1272                .data           = &sysctl_nr_trim_pages,
1273                .maxlen         = sizeof(sysctl_nr_trim_pages),
1274                .mode           = 0644,
1275                .proc_handler   = proc_dointvec_minmax,
1276                .extra1         = &zero,
1277        },
1278#endif
1279        {
1280                .procname       = "laptop_mode",
1281                .data           = &laptop_mode,
1282                .maxlen         = sizeof(laptop_mode),
1283                .mode           = 0644,
1284                .proc_handler   = proc_dointvec_jiffies,
1285        },
1286        {
1287                .procname       = "block_dump",
1288                .data           = &block_dump,
1289                .maxlen         = sizeof(block_dump),
1290                .mode           = 0644,
1291                .proc_handler   = proc_dointvec,
1292                .extra1         = &zero,
1293        },
1294        {
1295                .procname       = "vfs_cache_pressure",
1296                .data           = &sysctl_vfs_cache_pressure,
1297                .maxlen         = sizeof(sysctl_vfs_cache_pressure),
1298                .mode           = 0644,
1299                .proc_handler   = proc_dointvec,
1300                .extra1         = &zero,
1301        },
1302#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1303        {
1304                .procname       = "legacy_va_layout",
1305                .data           = &sysctl_legacy_va_layout,
1306                .maxlen         = sizeof(sysctl_legacy_va_layout),
1307                .mode           = 0644,
1308                .proc_handler   = proc_dointvec,
1309                .extra1         = &zero,
1310        },
1311#endif
1312#ifdef CONFIG_NUMA
1313        {
1314                .procname       = "zone_reclaim_mode",
1315                .data           = &zone_reclaim_mode,
1316                .maxlen         = sizeof(zone_reclaim_mode),
1317                .mode           = 0644,
1318                .proc_handler   = proc_dointvec,
1319                .extra1         = &zero,
1320        },
1321        {
1322                .procname       = "min_unmapped_ratio",
1323                .data           = &sysctl_min_unmapped_ratio,
1324                .maxlen         = sizeof(sysctl_min_unmapped_ratio),
1325                .mode           = 0644,
1326                .proc_handler   = sysctl_min_unmapped_ratio_sysctl_handler,
1327                .extra1         = &zero,
1328                .extra2         = &one_hundred,
1329        },
1330        {
1331                .procname       = "min_slab_ratio",
1332                .data           = &sysctl_min_slab_ratio,
1333                .maxlen         = sizeof(sysctl_min_slab_ratio),
1334                .mode           = 0644,
1335                .proc_handler   = sysctl_min_slab_ratio_sysctl_handler,
1336                .extra1         = &zero,
1337                .extra2         = &one_hundred,
1338        },
1339#endif
1340#ifdef CONFIG_SMP
1341        {
1342                .procname       = "stat_interval",
1343                .data           = &sysctl_stat_interval,
1344                .maxlen         = sizeof(sysctl_stat_interval),
1345                .mode           = 0644,
1346                .proc_handler   = proc_dointvec_jiffies,
1347        },
1348#endif
1349#ifdef CONFIG_MMU
1350        {
1351                .procname       = "mmap_min_addr",
1352                .data           = &dac_mmap_min_addr,
1353                .maxlen         = sizeof(unsigned long),
1354                .mode           = 0644,
1355                .proc_handler   = mmap_min_addr_handler,
1356        },
1357#endif
1358#ifdef CONFIG_NUMA
1359        {
1360                .procname       = "numa_zonelist_order",
1361                .data           = &numa_zonelist_order,
1362                .maxlen         = NUMA_ZONELIST_ORDER_LEN,
1363                .mode           = 0644,
1364                .proc_handler   = numa_zonelist_order_handler,
1365        },
1366#endif
1367#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1368   (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1369        {
1370                .procname       = "vdso_enabled",
1371                .data           = &vdso_enabled,
1372                .maxlen         = sizeof(vdso_enabled),
1373                .mode           = 0644,
1374                .proc_handler   = proc_dointvec,
1375                .extra1         = &zero,
1376        },
1377#endif
1378#ifdef CONFIG_HIGHMEM
1379        {
1380                .procname       = "highmem_is_dirtyable",
1381                .data           = &vm_highmem_is_dirtyable,
1382                .maxlen         = sizeof(vm_highmem_is_dirtyable),
1383                .mode           = 0644,
1384                .proc_handler   = proc_dointvec_minmax,
1385                .extra1         = &zero,
1386                .extra2         = &one,
1387        },
1388#endif
1389        {
1390                .procname       = "scan_unevictable_pages",
1391                .data           = &scan_unevictable_pages,
1392                .maxlen         = sizeof(scan_unevictable_pages),
1393                .mode           = 0644,
1394                .proc_handler   = scan_unevictable_handler,
1395        },
1396#ifdef CONFIG_MEMORY_FAILURE
1397        {
1398                .procname       = "memory_failure_early_kill",
1399                .data           = &sysctl_memory_failure_early_kill,
1400                .maxlen         = sizeof(sysctl_memory_failure_early_kill),
1401                .mode           = 0644,
1402                .proc_handler   = proc_dointvec_minmax,
1403                .extra1         = &zero,
1404                .extra2         = &one,
1405        },
1406        {
1407                .procname       = "memory_failure_recovery",
1408                .data           = &sysctl_memory_failure_recovery,
1409                .maxlen         = sizeof(sysctl_memory_failure_recovery),
1410                .mode           = 0644,
1411                .proc_handler   = proc_dointvec_minmax,
1412                .extra1         = &zero,
1413                .extra2         = &one,
1414        },
1415#endif
1416        { }
1417};
1418
1419#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1420static struct ctl_table binfmt_misc_table[] = {
1421        { }
1422};
1423#endif
1424
1425static struct ctl_table fs_table[] = {
1426        {
1427                .procname       = "inode-nr",
1428                .data           = &inodes_stat,
1429                .maxlen         = 2*sizeof(int),
1430                .mode           = 0444,
1431                .proc_handler   = proc_nr_inodes,
1432        },
1433        {
1434                .procname       = "inode-state",
1435                .data           = &inodes_stat,
1436                .maxlen         = 7*sizeof(int),
1437                .mode           = 0444,
1438                .proc_handler   = proc_nr_inodes,
1439        },
1440        {
1441                .procname       = "file-nr",
1442                .data           = &files_stat,
1443                .maxlen         = sizeof(files_stat),
1444                .mode           = 0444,
1445                .proc_handler   = proc_nr_files,
1446        },
1447        {
1448                .procname       = "file-max",
1449                .data           = &files_stat.max_files,
1450                .maxlen         = sizeof(files_stat.max_files),
1451                .mode           = 0644,
1452                .proc_handler   = proc_doulongvec_minmax,
1453        },
1454        {
1455                .procname       = "nr_open",
1456                .data           = &sysctl_nr_open,
1457                .maxlen         = sizeof(int),
1458                .mode           = 0644,
1459                .proc_handler   = proc_dointvec_minmax,
1460                .extra1         = &sysctl_nr_open_min,
1461                .extra2         = &sysctl_nr_open_max,
1462        },
1463        {
1464                .procname       = "dentry-state",
1465                .data           = &dentry_stat,
1466                .maxlen         = 6*sizeof(int),
1467                .mode           = 0444,
1468                .proc_handler   = proc_nr_dentry,
1469        },
1470        {
1471                .procname       = "overflowuid",
1472                .data           = &fs_overflowuid,
1473                .maxlen         = sizeof(int),
1474                .mode           = 0644,
1475                .proc_handler   = proc_dointvec_minmax,
1476                .extra1         = &minolduid,
1477                .extra2         = &maxolduid,
1478        },
1479        {
1480                .procname       = "overflowgid",
1481                .data           = &fs_overflowgid,
1482                .maxlen         = sizeof(int),
1483                .mode           = 0644,
1484                .proc_handler   = proc_dointvec_minmax,
1485                .extra1         = &minolduid,
1486                .extra2         = &maxolduid,
1487        },
1488#ifdef CONFIG_FILE_LOCKING
1489        {
1490                .procname       = "leases-enable",
1491                .data           = &leases_enable,
1492                .maxlen         = sizeof(int),
1493                .mode           = 0644,
1494                .proc_handler   = proc_dointvec,
1495        },
1496#endif
1497#ifdef CONFIG_DNOTIFY
1498        {
1499                .procname       = "dir-notify-enable",
1500                .data           = &dir_notify_enable,
1501                .maxlen         = sizeof(int),
1502                .mode           = 0644,
1503                .proc_handler   = proc_dointvec,
1504        },
1505#endif
1506#ifdef CONFIG_MMU
1507#ifdef CONFIG_FILE_LOCKING
1508        {
1509                .procname       = "lease-break-time",
1510                .data           = &lease_break_time,
1511                .maxlen         = sizeof(int),
1512                .mode           = 0644,
1513                .proc_handler   = proc_dointvec,
1514        },
1515#endif
1516#ifdef CONFIG_AIO
1517        {
1518                .procname       = "aio-nr",
1519                .data           = &aio_nr,
1520                .maxlen         = sizeof(aio_nr),
1521                .mode           = 0444,
1522                .proc_handler   = proc_doulongvec_minmax,
1523        },
1524        {
1525                .procname       = "aio-max-nr",
1526                .data           = &aio_max_nr,
1527                .maxlen         = sizeof(aio_max_nr),
1528                .mode           = 0644,
1529                .proc_handler   = proc_doulongvec_minmax,
1530        },
1531#endif /* CONFIG_AIO */
1532#ifdef CONFIG_INOTIFY_USER
1533        {
1534                .procname       = "inotify",
1535                .mode           = 0555,
1536                .child          = inotify_table,
1537        },
1538#endif  
1539#ifdef CONFIG_EPOLL
1540        {
1541                .procname       = "epoll",
1542                .mode           = 0555,
1543                .child          = epoll_table,
1544        },
1545#endif
1546#endif
1547        {
1548                .procname       = "protected_symlinks",
1549                .data           = &sysctl_protected_symlinks,
1550                .maxlen         = sizeof(int),
1551                .mode           = 0600,
1552                .proc_handler   = proc_dointvec_minmax,
1553                .extra1         = &zero,
1554                .extra2         = &one,
1555        },
1556        {
1557                .procname       = "protected_hardlinks",
1558                .data           = &sysctl_protected_hardlinks,
1559                .maxlen         = sizeof(int),
1560                .mode           = 0600,
1561                .proc_handler   = proc_dointvec_minmax,
1562                .extra1         = &zero,
1563                .extra2         = &one,
1564        },
1565        {
1566                .procname       = "suid_dumpable",
1567                .data           = &suid_dumpable,
1568                .maxlen         = sizeof(int),
1569                .mode           = 0644,
1570                .proc_handler   = proc_dointvec_minmax_coredump,
1571                .extra1         = &zero,
1572                .extra2         = &two,
1573        },
1574#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1575        {
1576                .procname       = "binfmt_misc",
1577                .mode           = 0555,
1578                .child          = binfmt_misc_table,
1579        },
1580#endif
1581        {
1582                .procname       = "pipe-max-size",
1583                .data           = &pipe_max_size,
1584                .maxlen         = sizeof(int),
1585                .mode           = 0644,
1586                .proc_handler   = &pipe_proc_fn,
1587                .extra1         = &pipe_min_size,
1588        },
1589        { }
1590};
1591
1592static struct ctl_table debug_table[] = {
1593#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1594        {
1595                .procname       = "exception-trace",
1596                .data           = &show_unhandled_signals,
1597                .maxlen         = sizeof(int),
1598                .mode           = 0644,
1599                .proc_handler   = proc_dointvec
1600        },
1601#endif
1602#if defined(CONFIG_OPTPROBES)
1603        {
1604                .procname       = "kprobes-optimization",
1605                .data           = &sysctl_kprobes_optimization,
1606                .maxlen         = sizeof(int),
1607                .mode           = 0644,
1608                .proc_handler   = proc_kprobes_optimization_handler,
1609                .extra1         = &zero,
1610                .extra2         = &one,
1611        },
1612#endif
1613        { }
1614};
1615
1616static struct ctl_table dev_table[] = {
1617        { }
1618};
1619
1620int __init sysctl_init(void)
1621{
1622        struct ctl_table_header *hdr;
1623
1624        hdr = register_sysctl_table(sysctl_base_table);
1625        kmemleak_not_leak(hdr);
1626        return 0;
1627}
1628
1629#endif /* CONFIG_SYSCTL */
1630
1631/*
1632 * /proc/sys support
1633 */
1634
1635#ifdef CONFIG_PROC_SYSCTL
1636
1637static int _proc_do_string(void* data, int maxlen, int write,
1638                           void __user *buffer,
1639                           size_t *lenp, loff_t *ppos)
1640{
1641        size_t len;
1642        char __user *p;
1643        char c;
1644
1645        if (!data || !maxlen || !*lenp) {
1646                *lenp = 0;
1647                return 0;
1648        }
1649
1650        if (write) {
1651                len = 0;
1652                p = buffer;
1653                while (len < *lenp) {
1654                        if (get_user(c, p++))
1655                                return -EFAULT;
1656                        if (c == 0 || c == '\n')
1657                                break;
1658                        len++;
1659                }
1660                if (len >= maxlen)
1661                        len = maxlen-1;
1662                if(copy_from_user(data, buffer, len))
1663                        return -EFAULT;
1664                ((char *) data)[len] = 0;
1665                *ppos += *lenp;
1666        } else {
1667                len = strlen(data);
1668                if (len > maxlen)
1669                        len = maxlen;
1670
1671                if (*ppos > len) {
1672                        *lenp = 0;
1673                        return 0;
1674                }
1675
1676                data += *ppos;
1677                len  -= *ppos;
1678
1679                if (len > *lenp)
1680                        len = *lenp;
1681                if (len)
1682                        if(copy_to_user(buffer, data, len))
1683                                return -EFAULT;
1684                if (len < *lenp) {
1685                        if(put_user('\n', ((char __user *) buffer) + len))
1686                                return -EFAULT;
1687                        len++;
1688                }
1689                *lenp = len;
1690                *ppos += len;
1691        }
1692        return 0;
1693}
1694
1695/**
1696 * proc_dostring - read a string sysctl
1697 * @table: the sysctl table
1698 * @write: %TRUE if this is a write to the sysctl file
1699 * @buffer: the user buffer
1700 * @lenp: the size of the user buffer
1701 * @ppos: file position
1702 *
1703 * Reads/writes a string from/to the user buffer. If the kernel
1704 * buffer provided is not large enough to hold the string, the
1705 * string is truncated. The copied string is %NULL-terminated.
1706 * If the string is being read by the user process, it is copied
1707 * and a newline '\n' is added. It is truncated if the buffer is
1708 * not large enough.
1709 *
1710 * Returns 0 on success.
1711 */
1712int proc_dostring(struct ctl_table *table, int write,
1713                  void __user *buffer, size_t *lenp, loff_t *ppos)
1714{
1715        return _proc_do_string(table->data, table->maxlen, write,
1716                               buffer, lenp, ppos);
1717}
1718
1719static size_t proc_skip_spaces(char **buf)
1720{
1721        size_t ret;
1722        char *tmp = skip_spaces(*buf);
1723        ret = tmp - *buf;
1724        *buf = tmp;
1725        return ret;
1726}
1727
1728static void proc_skip_char(char **buf, size_t *size, const char v)
1729{
1730        while (*size) {
1731                if (**buf != v)
1732                        break;
1733                (*size)--;
1734                (*buf)++;
1735        }
1736}
1737
1738#define TMPBUFLEN 22
1739/**
1740 * proc_get_long - reads an ASCII formatted integer from a user buffer
1741 *
1742 * @buf: a kernel buffer
1743 * @size: size of the kernel buffer
1744 * @val: this is where the number will be stored
1745 * @neg: set to %TRUE if number is negative
1746 * @perm_tr: a vector which contains the allowed trailers
1747 * @perm_tr_len: size of the perm_tr vector
1748 * @tr: pointer to store the trailer character
1749 *
1750 * In case of success %0 is returned and @buf and @size are updated with
1751 * the amount of bytes read. If @tr is non-NULL and a trailing
1752 * character exists (size is non-zero after returning from this
1753 * function), @tr is updated with the trailing character.
1754 */
1755static int proc_get_long(char **buf, size_t *size,
1756                          unsigned long *val, bool *neg,
1757                          const char *perm_tr, unsigned perm_tr_len, char *tr)
1758{
1759        int len;
1760        char *p, tmp[TMPBUFLEN];
1761
1762        if (!*size)
1763                return -EINVAL;
1764
1765        len = *size;
1766        if (len > TMPBUFLEN - 1)
1767                len = TMPBUFLEN - 1;
1768
1769        memcpy(tmp, *buf, len);
1770
1771        tmp[len] = 0;
1772        p = tmp;
1773        if (*p == '-' && *size > 1) {
1774                *neg = true;
1775                p++;
1776        } else
1777                *neg = false;
1778        if (!isdigit(*p))
1779                return -EINVAL;
1780
1781        *val = simple_strtoul(p, &p, 0);
1782
1783        len = p - tmp;
1784
1785        /* We don't know if the next char is whitespace thus we may accept
1786         * invalid integers (e.g. 1234...a) or two integers instead of one
1787         * (e.g. 123...1). So lets not allow such large numbers. */
1788        if (len == TMPBUFLEN - 1)
1789                return -EINVAL;
1790
1791        if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
1792                return -EINVAL;
1793
1794        if (tr && (len < *size))
1795                *tr = *p;
1796
1797        *buf += len;
1798        *size -= len;
1799
1800        return 0;
1801}
1802
1803/**
1804 * proc_put_long - converts an integer to a decimal ASCII formatted string
1805 *
1806 * @buf: the user buffer
1807 * @size: the size of the user buffer
1808 * @val: the integer to be converted
1809 * @neg: sign of the number, %TRUE for negative
1810 *
1811 * In case of success %0 is returned and @buf and @size are updated with
1812 * the amount of bytes written.
1813 */
1814static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
1815                          bool neg)
1816{
1817        int len;
1818        char tmp[TMPBUFLEN], *p = tmp;
1819
1820        sprintf(p, "%s%lu", neg ? "-" : "", val);
1821        len = strlen(tmp);
1822        if (len > *size)
1823                len = *size;
1824        if (copy_to_user(*buf, tmp, len))
1825                return -EFAULT;
1826        *size -= len;
1827        *buf += len;
1828        return 0;
1829}
1830#undef TMPBUFLEN
1831
1832static int proc_put_char(void __user **buf, size_t *size, char c)
1833{
1834        if (*size) {
1835                char __user **buffer = (char __user **)buf;
1836                if (put_user(c, *buffer))
1837                        return -EFAULT;
1838                (*size)--, (*buffer)++;
1839                *buf = *buffer;
1840        }
1841        return 0;
1842}
1843
1844static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
1845                                 int *valp,
1846                                 int write, void *data)
1847{
1848        if (write) {
1849                *valp = *negp ? -*lvalp : *lvalp;
1850        } else {
1851                int val = *valp;
1852                if (val < 0) {
1853                        *negp = true;
1854                        *lvalp = (unsigned long)-val;
1855                } else {
1856                        *negp = false;
1857                        *lvalp = (unsigned long)val;
1858                }
1859        }
1860        return 0;
1861}
1862
1863static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
1864
1865static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1866                  int write, void __user *buffer,
1867                  size_t *lenp, loff_t *ppos,
1868                  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1869                              int write, void *data),
1870                  void *data)
1871{
1872        int *i, vleft, first = 1, err = 0;
1873        unsigned long page = 0;
1874        size_t left;
1875        char *kbuf;
1876        
1877        if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
1878                *lenp = 0;
1879                return 0;
1880        }
1881        
1882        i = (int *) tbl_data;
1883        vleft = table->maxlen / sizeof(*i);
1884        left = *lenp;
1885
1886        if (!conv)
1887                conv = do_proc_dointvec_conv;
1888
1889        if (write) {
1890                if (left > PAGE_SIZE - 1)
1891                        left = PAGE_SIZE - 1;
1892                page = __get_free_page(GFP_TEMPORARY);
1893                kbuf = (char *) page;
1894                if (!kbuf)
1895                        return -ENOMEM;
1896                if (copy_from_user(kbuf, buffer, left)) {
1897                        err = -EFAULT;
1898                        goto free;
1899                }
1900                kbuf[left] = 0;
1901        }
1902
1903        for (; left && vleft--; i++, first=0) {
1904                unsigned long lval;
1905                bool neg;
1906
1907                if (write) {
1908                        left -= proc_skip_spaces(&kbuf);
1909
1910                        if (!left)
1911                                break;
1912                        err = proc_get_long(&kbuf, &left, &lval, &neg,
1913                                             proc_wspace_sep,
1914                                             sizeof(proc_wspace_sep), NULL);
1915                        if (err)
1916                                break;
1917                        if (conv(&neg, &lval, i, 1, data)) {
1918                                err = -EINVAL;
1919                                break;
1920                        }
1921                } else {
1922                        if (conv(&neg, &lval, i, 0, data)) {
1923                                err = -EINVAL;
1924                                break;
1925                        }
1926                        if (!first)
1927                                err = proc_put_char(&buffer, &left, '\t');
1928                        if (err)
1929                                break;
1930                        err = proc_put_long(&buffer, &left, lval, neg);
1931                        if (err)
1932                                break;
1933                }
1934        }
1935
1936        if (!write && !first && left && !err)
1937                err = proc_put_char(&buffer, &left, '\n');
1938        if (write && !err && left)
1939                left -= proc_skip_spaces(&kbuf);
1940free:
1941        if (write) {
1942                free_page(page);
1943                if (first)
1944                        return err ? : -EINVAL;
1945        }
1946        *lenp -= left;
1947        *ppos += *lenp;
1948        return err;
1949}
1950
1951static int do_proc_dointvec(struct ctl_table *table, int write,
1952                  void __user *buffer, size_t *lenp, loff_t *ppos,
1953                  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
1954                              int write, void *data),
1955                  void *data)
1956{
1957        return __do_proc_dointvec(table->data, table, write,
1958                        buffer, lenp, ppos, conv, data);
1959}
1960
1961/**
1962 * proc_dointvec - read a vector of integers
1963 * @table: the sysctl table
1964 * @write: %TRUE if this is a write to the sysctl file
1965 * @buffer: the user buffer
1966 * @lenp: the size of the user buffer
1967 * @ppos: file position
1968 *
1969 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1970 * values from/to the user buffer, treated as an ASCII string. 
1971 *
1972 * Returns 0 on success.
1973 */
1974int proc_dointvec(struct ctl_table *table, int write,
1975                     void __user *buffer, size_t *lenp, loff_t *ppos)
1976{
1977    return do_proc_dointvec(table,write,buffer,lenp,ppos,
1978                            NULL,NULL);
1979}
1980
1981/*
1982 * Taint values can only be increased
1983 * This means we can safely use a temporary.
1984 */
1985static int proc_taint(struct ctl_table *table, int write,
1986                               void __user *buffer, size_t *lenp, loff_t *ppos)
1987{
1988        struct ctl_table t;
1989        unsigned long tmptaint = get_taint();
1990        int err;
1991
1992        if (write && !capable(CAP_SYS_ADMIN))
1993                return -EPERM;
1994
1995        t = *table;
1996        t.data = &tmptaint;
1997        err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
1998        if (err < 0)
1999                return err;
2000
2001        if (write) {
2002                /*
2003                 * Poor man's atomic or. Not worth adding a primitive
2004                 * to everyone's atomic.h for this
2005                 */
2006                int i;
2007                for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2008                        if ((tmptaint >> i) & 1)
2009                                add_taint(i);
2010                }
2011        }
2012
2013        return err;
2014}
2015
2016#ifdef CONFIG_PRINTK
2017static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2018                                void __user *buffer, size_t *lenp, loff_t *ppos)
2019{
2020        if (write && !capable(CAP_SYS_ADMIN))
2021                return -EPERM;
2022
2023        return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2024}
2025#endif
2026
2027struct do_proc_dointvec_minmax_conv_param {
2028        int *min;
2029        int *max;
2030};
2031
2032static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2033                                        int *valp,
2034                                        int write, void *data)
2035{
2036        struct do_proc_dointvec_minmax_conv_param *param = data;
2037        if (write) {
2038                int val = *negp ? -*lvalp : *lvalp;
2039                if ((param->min && *param->min > val) ||
2040                    (param->max && *param->max < val))
2041                        return -EINVAL;
2042                *valp = val;
2043        } else {
2044                int val = *valp;
2045                if (val < 0) {
2046                        *negp = true;
2047                        *lvalp = (unsigned long)-val;
2048                } else {
2049                        *negp = false;
2050                        *lvalp = (unsigned long)val;
2051                }
2052        }
2053        return 0;
2054}
2055
2056/**
2057 * proc_dointvec_minmax - read a vector of integers with min/max values
2058 * @table: the sysctl table
2059 * @write: %TRUE if this is a write to the sysctl file
2060 * @buffer: the user buffer
2061 * @lenp: the size of the user buffer
2062 * @ppos: file position
2063 *
2064 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2065 * values from/to the user buffer, treated as an ASCII string.
2066 *
2067 * This routine will ensure the values are within the range specified by
2068 * table->extra1 (min) and table->extra2 (max).
2069 *
2070 * Returns 0 on success.
2071 */
2072int proc_dointvec_minmax(struct ctl_table *table, int write,
2073                  void __user *buffer, size_t *lenp, loff_t *ppos)
2074{
2075        struct do_proc_dointvec_minmax_conv_param param = {
2076                .min = (int *) table->extra1,
2077                .max = (int *) table->extra2,
2078        };
2079        return do_proc_dointvec(table, write, buffer, lenp, ppos,
2080                                do_proc_dointvec_minmax_conv, &param);
2081}
2082
2083static void validate_coredump_safety(void)
2084{
2085#ifdef CONFIG_COREDUMP
2086        if (suid_dumpable == SUID_DUMPABLE_SAFE &&
2087            core_pattern[0] != '/' && core_pattern[0] != '|') {
2088                printk(KERN_WARNING "Unsafe core_pattern used with "\
2089                        "suid_dumpable=2. Pipe handler or fully qualified "\
2090                        "core dump path required.\n");
2091        }
2092#endif
2093}
2094
2095static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2096                void __user *buffer, size_t *lenp, loff_t *ppos)
2097{
2098        int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2099        if (!error)
2100                validate_coredump_safety();
2101        return error;
2102}
2103
2104#ifdef CONFIG_COREDUMP
2105static int proc_dostring_coredump(struct ctl_table *table, int write,
2106                  void __user *buffer, size_t *lenp, loff_t *ppos)
2107{
2108        int error = proc_dostring(table, write, buffer, lenp, ppos);
2109        if (!error)
2110                validate_coredump_safety();
2111        return error;
2112}
2113#endif
2114
2115static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2116                                     void __user *buffer,
2117                                     size_t *lenp, loff_t *ppos,
2118                                     unsigned long convmul,
2119                                     unsigned long convdiv)
2120{
2121        unsigned long *i, *min, *max;
2122        int vleft, first = 1, err = 0;
2123        unsigned long page = 0;
2124        size_t left;
2125        char *kbuf;
2126
2127        if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2128                *lenp = 0;
2129                return 0;
2130        }
2131
2132        i = (unsigned long *) data;
2133        min = (unsigned long *) table->extra1;
2134        max = (unsigned long *) table->extra2;
2135        vleft = table->maxlen / sizeof(unsigned long);
2136        left = *lenp;
2137
2138        if (write) {
2139                if (left > PAGE_SIZE - 1)
2140                        left = PAGE_SIZE - 1;
2141                page = __get_free_page(GFP_TEMPORARY);
2142                kbuf = (char *) page;
2143                if (!kbuf)
2144                        return -ENOMEM;
2145                if (copy_from_user(kbuf, buffer, left)) {
2146                        err = -EFAULT;
2147                        goto free;
2148                }
2149                kbuf[left] = 0;
2150        }
2151
2152        for (; left && vleft--; i++, first = 0) {
2153                unsigned long val;
2154
2155                if (write) {
2156                        bool neg;
2157
2158                        left -= proc_skip_spaces(&kbuf);
2159
2160                        err = proc_get_long(&kbuf, &left, &val, &neg,
2161                                             proc_wspace_sep,
2162                                             sizeof(proc_wspace_sep), NULL);
2163                        if (err)
2164                                break;
2165                        if (neg)
2166                                continue;
2167                        if ((min && val < *min) || (max && val > *max))
2168                                continue;
2169                        *i = val;
2170                } else {
2171                        val = convdiv * (*i) / convmul;
2172                        if (!first)
2173                                err = proc_put_char(&buffer, &left, '\t');
2174                        err = proc_put_long(&buffer, &left, val, false);
2175                        if (err)
2176                                break;
2177                }
2178        }
2179
2180        if (!write && !first && left && !err)
2181                err = proc_put_char(&buffer, &left, '\n');
2182        if (write && !err)
2183                left -= proc_skip_spaces(&kbuf);
2184free:
2185        if (write) {
2186                free_page(page);
2187                if (first)
2188                        return err ? : -EINVAL;
2189        }
2190        *lenp -= left;
2191        *ppos += *lenp;
2192        return err;
2193}
2194
2195static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2196                                     void __user *buffer,
2197                                     size_t *lenp, loff_t *ppos,
2198                                     unsigned long convmul,
2199                                     unsigned long convdiv)
2200{
2201        return __do_proc_doulongvec_minmax(table->data, table, write,
2202                        buffer, lenp, ppos, convmul, convdiv);
2203}
2204
2205/**
2206 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2207 * @table: the sysctl table
2208 * @write: %TRUE if this is a write to the sysctl file
2209 * @buffer: the user buffer
2210 * @lenp: the size of the user buffer
2211 * @ppos: file position
2212 *
2213 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2214 * values from/to the user buffer, treated as an ASCII string.
2215 *
2216 * This routine will ensure the values are within the range specified by
2217 * table->extra1 (min) and table->extra2 (max).
2218 *
2219 * Returns 0 on success.
2220 */
2221int proc_doulongvec_minmax(struct ctl_table *table, int write,
2222                           void __user *buffer, size_t *lenp, loff_t *ppos)
2223{
2224    return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2225}
2226
2227/**
2228 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2229 * @table: the sysctl table
2230 * @write: %TRUE if this is a write to the sysctl file
2231 * @buffer: the user buffer
2232 * @lenp: the size of the user buffer
2233 * @ppos: file position
2234 *
2235 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2236 * values from/to the user buffer, treated as an ASCII string. The values
2237 * are treated as milliseconds, and converted to jiffies when they are stored.
2238 *
2239 * This routine will ensure the values are within the range specified by
2240 * table->extra1 (min) and table->extra2 (max).
2241 *
2242 * Returns 0 on success.
2243 */
2244int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2245                                      void __user *buffer,
2246                                      size_t *lenp, loff_t *ppos)
2247{
2248    return do_proc_doulongvec_minmax(table, write, buffer,
2249                                     lenp, ppos, HZ, 1000l);
2250}
2251
2252
2253static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2254                                         int *valp,
2255                                         int write, void *data)
2256{
2257        if (write) {
2258                if (*lvalp > LONG_MAX / HZ)
2259                        return 1;
2260                *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2261        } else {
2262                int val = *valp;
2263                unsigned long lval;
2264                if (val < 0) {
2265                        *negp = true;
2266                        lval = (unsigned long)-val;
2267                } else {
2268                        *negp = false;
2269                        lval = (unsigned long)val;
2270                }
2271                *lvalp = lval / HZ;
2272        }
2273        return 0;
2274}
2275
2276static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2277                                                int *valp,
2278                                                int write, void *data)
2279{
2280        if (write) {
2281                if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2282                        return 1;
2283                *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2284        } else {
2285                int val = *valp;
2286                unsigned long lval;
2287                if (val < 0) {
2288                        *negp = true;
2289                        lval = (unsigned long)-val;
2290                } else {
2291                        *negp = false;
2292                        lval = (unsigned long)val;
2293                }
2294                *lvalp = jiffies_to_clock_t(lval);
2295        }
2296        return 0;
2297}
2298
2299static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2300                                            int *valp,
2301                                            int write, void *data)
2302{
2303        if (write) {
2304                *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2305        } else {
2306                int val = *valp;
2307                unsigned long lval;
2308                if (val < 0) {
2309                        *negp = true;
2310                        lval = (unsigned long)-val;
2311                } else {
2312                        *negp = false;
2313                        lval = (unsigned long)val;
2314                }
2315                *lvalp = jiffies_to_msecs(lval);
2316        }
2317        return 0;
2318}
2319
2320/**
2321 * proc_dointvec_jiffies - read a vector of integers as seconds
2322 * @table: the sysctl table
2323 * @write: %TRUE if this is a write to the sysctl file
2324 * @buffer: the user buffer
2325 * @lenp: the size of the user buffer
2326 * @ppos: file position
2327 *
2328 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2329 * values from/to the user buffer, treated as an ASCII string. 
2330 * The values read are assumed to be in seconds, and are converted into
2331 * jiffies.
2332 *
2333 * Returns 0 on success.
2334 */
2335int proc_dointvec_jiffies(struct ctl_table *table, int write,
2336                          void __user *buffer, size_t *lenp, loff_t *ppos)
2337{
2338    return do_proc_dointvec(table,write,buffer,lenp,ppos,
2339                            do_proc_dointvec_jiffies_conv,NULL);
2340}
2341
2342/**
2343 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2344 * @table: the sysctl table
2345 * @write: %TRUE if this is a write to the sysctl file
2346 * @buffer: the user buffer
2347 * @lenp: the size of the user buffer
2348 * @ppos: pointer to the file position
2349 *
2350 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2351 * values from/to the user buffer, treated as an ASCII string. 
2352 * The values read are assumed to be in 1/USER_HZ seconds, and 
2353 * are converted into jiffies.
2354 *
2355 * Returns 0 on success.
2356 */
2357int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2358                                 void __user *buffer, size_t *lenp, loff_t *ppos)
2359{
2360    return do_proc_dointvec(table,write,buffer,lenp,ppos,
2361                            do_proc_dointvec_userhz_jiffies_conv,NULL);
2362}
2363
2364/**
2365 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2366 * @table: the sysctl table
2367 * @write: %TRUE if this is a write to the sysctl file
2368 * @buffer: the user buffer
2369 * @lenp: the size of the user buffer
2370 * @ppos: file position
2371 * @ppos: the current position in the file
2372 *
2373 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2374 * values from/to the user buffer, treated as an ASCII string. 
2375 * The values read are assumed to be in 1/1000 seconds, and 
2376 * are converted into jiffies.
2377 *
2378 * Returns 0 on success.
2379 */
2380int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2381                             void __user *buffer, size_t *lenp, loff_t *ppos)
2382{
2383        return do_proc_dointvec(table, write, buffer, lenp, ppos,
2384                                do_proc_dointvec_ms_jiffies_conv, NULL);
2385}
2386
2387static int proc_do_cad_pid(struct ctl_table *table, int write,
2388                           void __user *buffer, size_t *lenp, loff_t *ppos)
2389{
2390        struct pid *new_pid;
2391        pid_t tmp;
2392        int r;
2393
2394        tmp = pid_vnr(cad_pid);
2395
2396        r = __do_proc_dointvec(&tmp, table, write, buffer,
2397                               lenp, ppos, NULL, NULL);
2398        if (r || !write)
2399                return r;
2400
2401        new_pid = find_get_pid(tmp);
2402        if (!new_pid)
2403                return -ESRCH;
2404
2405        put_pid(xchg(&cad_pid, new_pid));
2406        return 0;
2407}
2408
2409/**
2410 * proc_do_large_bitmap - read/write from/to a large bitmap
2411 * @table: the sysctl table
2412 * @write: %TRUE if this is a write to the sysctl file
2413 * @buffer: the user buffer
2414 * @lenp: the size of the user buffer
2415 * @ppos: file position
2416 *
2417 * The bitmap is stored at table->data and the bitmap length (in bits)
2418 * in table->maxlen.
2419 *
2420 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2421 * large bitmaps may be represented in a compact manner. Writing into
2422 * the file will clear the bitmap then update it with the given input.
2423 *
2424 * Returns 0 on success.
2425 */
2426int proc_do_large_bitmap(struct ctl_table *table, int write,
2427                         void __user *buffer, size_t *lenp, loff_t *ppos)
2428{
2429        int err = 0;
2430        bool first = 1;
2431        size_t left = *lenp;
2432        unsigned long bitmap_len = table->maxlen;
2433        unsigned long *bitmap = (unsigned long *) table->data;
2434        unsigned long *tmp_bitmap = NULL;
2435        char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2436
2437        if (!bitmap_len || !left || (*ppos && !write)) {
2438                *lenp = 0;
2439                return 0;
2440        }
2441
2442        if (write) {
2443                unsigned long page = 0;
2444                char *kbuf;
2445
2446                if (left > PAGE_SIZE - 1)
2447                        left = PAGE_SIZE - 1;
2448
2449                page = __get_free_page(GFP_TEMPORARY);
2450                kbuf = (char *) page;
2451                if (!kbuf)
2452                        return -ENOMEM;
2453                if (copy_from_user(kbuf, buffer, left)) {
2454                        free_page(page);
2455                        return -EFAULT;
2456                }
2457                kbuf[left] = 0;
2458
2459                tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2460                                     GFP_KERNEL);
2461                if (!tmp_bitmap) {
2462                        free_page(page);
2463                        return -ENOMEM;
2464                }
2465                proc_skip_char(&kbuf, &left, '\n');
2466                while (!err && left) {
2467                        unsigned long val_a, val_b;
2468                        bool neg;
2469
2470                        err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2471                                             sizeof(tr_a), &c);
2472                        if (err)
2473                                break;
2474                        if (val_a >= bitmap_len || neg) {
2475                                err = -EINVAL;
2476                                break;
2477                        }
2478
2479                        val_b = val_a;
2480                        if (left) {
2481                                kbuf++;
2482                                left--;
2483                        }
2484
2485                        if (c == '-') {
2486                                err = proc_get_long(&kbuf, &left, &val_b,
2487                                                     &neg, tr_b, sizeof(tr_b),
2488                                                     &c);
2489                                if (err)
2490                                        break;
2491                                if (val_b >= bitmap_len || neg ||
2492                                    val_a > val_b) {
2493                                        err = -EINVAL;
2494                                        break;
2495                                }
2496                                if (left) {
2497                                        kbuf++;
2498                                        left--;
2499                                }
2500                        }
2501
2502                        bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2503                        first = 0;
2504                        proc_skip_char(&kbuf, &left, '\n');
2505                }
2506                free_page(page);
2507        } else {
2508                unsigned long bit_a, bit_b = 0;
2509
2510                while (left) {
2511                        bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2512                        if (bit_a >= bitmap_len)
2513                                break;
2514                        bit_b = find_next_zero_bit(bitmap, bitmap_len,
2515                                                   bit_a + 1) - 1;
2516
2517                        if (!first) {
2518                                err = proc_put_char(&buffer, &left, ',');
2519                                if (err)
2520                                        break;
2521                        }
2522                        err = proc_put_long(&buffer, &left, bit_a, false);
2523                        if (err)
2524                                break;
2525                        if (bit_a != bit_b) {
2526                                err = proc_put_char(&buffer, &left, '-');
2527                                if (err)
2528                                        break;
2529                                err = proc_put_long(&buffer, &left, bit_b, false);
2530                                if (err)
2531                                        break;
2532                        }
2533
2534                        first = 0; bit_b++;
2535                }
2536                if (!err)
2537                        err = proc_put_char(&buffer, &left, '\n');
2538        }
2539
2540        if (!err) {
2541                if (write) {
2542                        if (*ppos)
2543                                bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2544                        else
2545                                bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2546                }
2547                kfree(tmp_bitmap);
2548                *lenp -= left;
2549                *ppos += *lenp;
2550                return 0;
2551        } else {
2552                kfree(tmp_bitmap);
2553                return err;
2554        }
2555}
2556
2557#else /* CONFIG_PROC_SYSCTL */
2558
2559int proc_dostring(struct ctl_table *table, int write,
2560                  void __user *buffer, size_t *lenp, loff_t *ppos)
2561{
2562        return -ENOSYS;
2563}
2564
2565int proc_dointvec(struct ctl_table *table, int write,
2566                  void __user *buffer, size_t *lenp, loff_t *ppos)
2567{
2568        return -ENOSYS;
2569}
2570
2571int proc_dointvec_minmax(struct ctl_table *table, int write,
2572                    void __user *buffer, size_t *lenp, loff_t *ppos)
2573{
2574        return -ENOSYS;
2575}
2576
2577int proc_dointvec_jiffies(struct ctl_table *table, int write,
2578                    void __user *buffer, size_t *lenp, loff_t *ppos)
2579{
2580        return -ENOSYS;
2581}
2582
2583int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2584                    void __user *buffer, size_t *lenp, loff_t *ppos)
2585{
2586        return -ENOSYS;
2587}
2588
2589int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2590                             void __user *buffer, size_t *lenp, loff_t *ppos)
2591{
2592        return -ENOSYS;
2593}
2594
2595int proc_doulongvec_minmax(struct ctl_table *table, int write,
2596                    void __user *buffer, size_t *lenp, loff_t *ppos)
2597{
2598        return -ENOSYS;
2599}
2600
2601int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2602                                      void __user *buffer,
2603                                      size_t *lenp, loff_t *ppos)
2604{
2605    return -ENOSYS;
2606}
2607
2608
2609#endif /* CONFIG_PROC_SYSCTL */
2610
2611/*
2612 * No sense putting this after each symbol definition, twice,
2613 * exception granted :-)
2614 */
2615EXPORT_SYMBOL(proc_dointvec);
2616EXPORT_SYMBOL(proc_dointvec_jiffies);
2617EXPORT_SYMBOL(proc_dointvec_minmax);
2618EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2619EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2620EXPORT_SYMBOL(proc_dostring);
2621EXPORT_SYMBOL(proc_doulongvec_minmax);
2622EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2623
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.