sysctl.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505
  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. #include <linux/module.h>
  21. #include <linux/mm.h>
  22. #include <linux/swap.h>
  23. #include <linux/slab.h>
  24. #include <linux/sysctl.h>
  25. #include <linux/proc_fs.h>
  26. #include <linux/capability.h>
  27. #include <linux/ctype.h>
  28. #include <linux/utsname.h>
  29. #include <linux/capability.h>
  30. #include <linux/smp_lock.h>
  31. #include <linux/init.h>
  32. #include <linux/kernel.h>
  33. #include <linux/kobject.h>
  34. #include <linux/net.h>
  35. #include <linux/sysrq.h>
  36. #include <linux/highuid.h>
  37. #include <linux/writeback.h>
  38. #include <linux/hugetlb.h>
  39. #include <linux/security.h>
  40. #include <linux/initrd.h>
  41. #include <linux/times.h>
  42. #include <linux/limits.h>
  43. #include <linux/dcache.h>
  44. #include <linux/syscalls.h>
  45. #include <linux/nfs_fs.h>
  46. #include <linux/acpi.h>
  47. #include <asm/uaccess.h>
  48. #include <asm/processor.h>
  49. extern int proc_nr_files(ctl_table *table, int write, struct file *filp,
  50. void __user *buffer, size_t *lenp, loff_t *ppos);
  51. #ifdef CONFIG_X86
  52. #include <asm/nmi.h>
  53. #include <asm/stacktrace.h>
  54. #endif
  55. #if defined(CONFIG_SYSCTL)
  56. /* External variables not in a header file. */
  57. extern int C_A_D;
  58. extern int print_fatal_signals;
  59. extern int sysctl_overcommit_memory;
  60. extern int sysctl_overcommit_ratio;
  61. extern int sysctl_panic_on_oom;
  62. extern int max_threads;
  63. extern int core_uses_pid;
  64. extern int suid_dumpable;
  65. extern char core_pattern[];
  66. extern int pid_max;
  67. extern int min_free_kbytes;
  68. extern int printk_ratelimit_jiffies;
  69. extern int printk_ratelimit_burst;
  70. extern int pid_max_min, pid_max_max;
  71. extern int sysctl_drop_caches;
  72. extern int percpu_pagelist_fraction;
  73. extern int compat_log;
  74. extern int maps_protect;
  75. extern int sysctl_stat_interval;
  76. /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
  77. static int maxolduid = 65535;
  78. static int minolduid;
  79. static int min_percpu_pagelist_fract = 8;
  80. static int ngroups_max = NGROUPS_MAX;
  81. #ifdef CONFIG_KMOD
  82. extern char modprobe_path[];
  83. #endif
  84. #ifdef CONFIG_CHR_DEV_SG
  85. extern int sg_big_buff;
  86. #endif
  87. #ifdef __sparc__
  88. extern char reboot_command [];
  89. extern int stop_a_enabled;
  90. extern int scons_pwroff;
  91. #endif
  92. #ifdef __hppa__
  93. extern int pwrsw_enabled;
  94. extern int unaligned_enabled;
  95. #endif
  96. #ifdef CONFIG_S390
  97. #ifdef CONFIG_MATHEMU
  98. extern int sysctl_ieee_emulation_warnings;
  99. #endif
  100. extern int sysctl_userprocess_debug;
  101. extern int spin_retry;
  102. #endif
  103. extern int sysctl_hz_timer;
  104. #ifdef CONFIG_BSD_PROCESS_ACCT
  105. extern int acct_parm[];
  106. #endif
  107. #ifdef CONFIG_IA64
  108. extern int no_unaligned_warning;
  109. #endif
  110. #ifdef CONFIG_RT_MUTEXES
  111. extern int max_lock_depth;
  112. #endif
  113. #ifdef CONFIG_SYSCTL_SYSCALL
  114. static int parse_table(int __user *, int, void __user *, size_t __user *,
  115. void __user *, size_t, ctl_table *);
  116. #endif
  117. #ifdef CONFIG_PROC_SYSCTL
  118. static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
  119. void __user *buffer, size_t *lenp, loff_t *ppos);
  120. static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
  121. void __user *buffer, size_t *lenp, loff_t *ppos);
  122. #endif
  123. static ctl_table root_table[];
  124. static struct ctl_table_header root_table_header =
  125. { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
  126. static ctl_table kern_table[];
  127. static ctl_table vm_table[];
  128. static ctl_table fs_table[];
  129. static ctl_table debug_table[];
  130. static ctl_table dev_table[];
  131. extern ctl_table random_table[];
  132. #ifdef CONFIG_UNIX98_PTYS
  133. extern ctl_table pty_table[];
  134. #endif
  135. #ifdef CONFIG_INOTIFY_USER
  136. extern ctl_table inotify_table[];
  137. #endif
  138. #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
  139. int sysctl_legacy_va_layout;
  140. #endif
  141. /* The default sysctl tables: */
  142. static ctl_table root_table[] = {
  143. {
  144. .ctl_name = CTL_KERN,
  145. .procname = "kernel",
  146. .mode = 0555,
  147. .child = kern_table,
  148. },
  149. {
  150. .ctl_name = CTL_VM,
  151. .procname = "vm",
  152. .mode = 0555,
  153. .child = vm_table,
  154. },
  155. #ifdef CONFIG_NET
  156. {
  157. .ctl_name = CTL_NET,
  158. .procname = "net",
  159. .mode = 0555,
  160. .child = net_table,
  161. },
  162. #endif
  163. {
  164. .ctl_name = CTL_FS,
  165. .procname = "fs",
  166. .mode = 0555,
  167. .child = fs_table,
  168. },
  169. {
  170. .ctl_name = CTL_DEBUG,
  171. .procname = "debug",
  172. .mode = 0555,
  173. .child = debug_table,
  174. },
  175. {
  176. .ctl_name = CTL_DEV,
  177. .procname = "dev",
  178. .mode = 0555,
  179. .child = dev_table,
  180. },
  181. { .ctl_name = 0 }
  182. };
  183. #ifdef CONFIG_SCHED_DEBUG
  184. static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
  185. static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
  186. static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
  187. static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
  188. #endif
  189. static ctl_table kern_table[] = {
  190. #ifdef CONFIG_SCHED_DEBUG
  191. {
  192. .ctl_name = CTL_UNNUMBERED,
  193. .procname = "sched_granularity_ns",
  194. .data = &sysctl_sched_granularity,
  195. .maxlen = sizeof(unsigned int),
  196. .mode = 0644,
  197. .proc_handler = &proc_dointvec_minmax,
  198. .strategy = &sysctl_intvec,
  199. .extra1 = &min_sched_granularity_ns,
  200. .extra2 = &max_sched_granularity_ns,
  201. },
  202. {
  203. .ctl_name = CTL_UNNUMBERED,
  204. .procname = "sched_wakeup_granularity_ns",
  205. .data = &sysctl_sched_wakeup_granularity,
  206. .maxlen = sizeof(unsigned int),
  207. .mode = 0644,
  208. .proc_handler = &proc_dointvec_minmax,
  209. .strategy = &sysctl_intvec,
  210. .extra1 = &min_wakeup_granularity_ns,
  211. .extra2 = &max_wakeup_granularity_ns,
  212. },
  213. {
  214. .ctl_name = CTL_UNNUMBERED,
  215. .procname = "sched_batch_wakeup_granularity_ns",
  216. .data = &sysctl_sched_batch_wakeup_granularity,
  217. .maxlen = sizeof(unsigned int),
  218. .mode = 0644,
  219. .proc_handler = &proc_dointvec_minmax,
  220. .strategy = &sysctl_intvec,
  221. .extra1 = &min_wakeup_granularity_ns,
  222. .extra2 = &max_wakeup_granularity_ns,
  223. },
  224. {
  225. .ctl_name = CTL_UNNUMBERED,
  226. .procname = "sched_stat_granularity_ns",
  227. .data = &sysctl_sched_stat_granularity,
  228. .maxlen = sizeof(unsigned int),
  229. .mode = 0644,
  230. .proc_handler = &proc_dointvec_minmax,
  231. .strategy = &sysctl_intvec,
  232. .extra1 = &min_wakeup_granularity_ns,
  233. .extra2 = &max_wakeup_granularity_ns,
  234. },
  235. {
  236. .ctl_name = CTL_UNNUMBERED,
  237. .procname = "sched_runtime_limit_ns",
  238. .data = &sysctl_sched_runtime_limit,
  239. .maxlen = sizeof(unsigned int),
  240. .mode = 0644,
  241. .proc_handler = &proc_dointvec_minmax,
  242. .strategy = &sysctl_intvec,
  243. .extra1 = &min_sched_granularity_ns,
  244. .extra2 = &max_sched_granularity_ns,
  245. },
  246. {
  247. .ctl_name = CTL_UNNUMBERED,
  248. .procname = "sched_child_runs_first",
  249. .data = &sysctl_sched_child_runs_first,
  250. .maxlen = sizeof(unsigned int),
  251. .mode = 0644,
  252. .proc_handler = &proc_dointvec,
  253. },
  254. {
  255. .ctl_name = CTL_UNNUMBERED,
  256. .procname = "sched_features",
  257. .data = &sysctl_sched_features,
  258. .maxlen = sizeof(unsigned int),
  259. .mode = 0644,
  260. .proc_handler = &proc_dointvec,
  261. },
  262. #endif
  263. {
  264. .ctl_name = KERN_PANIC,
  265. .procname = "panic",
  266. .data = &panic_timeout,
  267. .maxlen = sizeof(int),
  268. .mode = 0644,
  269. .proc_handler = &proc_dointvec,
  270. },
  271. {
  272. .ctl_name = KERN_CORE_USES_PID,
  273. .procname = "core_uses_pid",
  274. .data = &core_uses_pid,
  275. .maxlen = sizeof(int),
  276. .mode = 0644,
  277. .proc_handler = &proc_dointvec,
  278. },
  279. {
  280. .ctl_name = KERN_CORE_PATTERN,
  281. .procname = "core_pattern",
  282. .data = core_pattern,
  283. .maxlen = CORENAME_MAX_SIZE,
  284. .mode = 0644,
  285. .proc_handler = &proc_dostring,
  286. .strategy = &sysctl_string,
  287. },
  288. #ifdef CONFIG_PROC_SYSCTL
  289. {
  290. .ctl_name = KERN_TAINTED,
  291. .procname = "tainted",
  292. .data = &tainted,
  293. .maxlen = sizeof(int),
  294. .mode = 0644,
  295. .proc_handler = &proc_dointvec_taint,
  296. },
  297. #endif
  298. {
  299. .ctl_name = KERN_CAP_BSET,
  300. .procname = "cap-bound",
  301. .data = &cap_bset,
  302. .maxlen = sizeof(kernel_cap_t),
  303. .mode = 0600,
  304. .proc_handler = &proc_dointvec_bset,
  305. },
  306. #ifdef CONFIG_BLK_DEV_INITRD
  307. {
  308. .ctl_name = KERN_REALROOTDEV,
  309. .procname = "real-root-dev",
  310. .data = &real_root_dev,
  311. .maxlen = sizeof(int),
  312. .mode = 0644,
  313. .proc_handler = &proc_dointvec,
  314. },
  315. #endif
  316. {
  317. .ctl_name = CTL_UNNUMBERED,
  318. .procname = "print-fatal-signals",
  319. .data = &print_fatal_signals,
  320. .maxlen = sizeof(int),
  321. .mode = 0644,
  322. .proc_handler = &proc_dointvec,
  323. },
  324. #ifdef __sparc__
  325. {
  326. .ctl_name = KERN_SPARC_REBOOT,
  327. .procname = "reboot-cmd",
  328. .data = reboot_command,
  329. .maxlen = 256,
  330. .mode = 0644,
  331. .proc_handler = &proc_dostring,
  332. .strategy = &sysctl_string,
  333. },
  334. {
  335. .ctl_name = KERN_SPARC_STOP_A,
  336. .procname = "stop-a",
  337. .data = &stop_a_enabled,
  338. .maxlen = sizeof (int),
  339. .mode = 0644,
  340. .proc_handler = &proc_dointvec,
  341. },
  342. {
  343. .ctl_name = KERN_SPARC_SCONS_PWROFF,
  344. .procname = "scons-poweroff",
  345. .data = &scons_pwroff,
  346. .maxlen = sizeof (int),
  347. .mode = 0644,
  348. .proc_handler = &proc_dointvec,
  349. },
  350. #endif
  351. #ifdef __hppa__
  352. {
  353. .ctl_name = KERN_HPPA_PWRSW,
  354. .procname = "soft-power",
  355. .data = &pwrsw_enabled,
  356. .maxlen = sizeof (int),
  357. .mode = 0644,
  358. .proc_handler = &proc_dointvec,
  359. },
  360. {
  361. .ctl_name = KERN_HPPA_UNALIGNED,
  362. .procname = "unaligned-trap",
  363. .data = &unaligned_enabled,
  364. .maxlen = sizeof (int),
  365. .mode = 0644,
  366. .proc_handler = &proc_dointvec,
  367. },
  368. #endif
  369. {
  370. .ctl_name = KERN_CTLALTDEL,
  371. .procname = "ctrl-alt-del",
  372. .data = &C_A_D,
  373. .maxlen = sizeof(int),
  374. .mode = 0644,
  375. .proc_handler = &proc_dointvec,
  376. },
  377. {
  378. .ctl_name = KERN_PRINTK,
  379. .procname = "printk",
  380. .data = &console_loglevel,
  381. .maxlen = 4*sizeof(int),
  382. .mode = 0644,
  383. .proc_handler = &proc_dointvec,
  384. },
  385. #ifdef CONFIG_KMOD
  386. {
  387. .ctl_name = KERN_MODPROBE,
  388. .procname = "modprobe",
  389. .data = &modprobe_path,
  390. .maxlen = KMOD_PATH_LEN,
  391. .mode = 0644,
  392. .proc_handler = &proc_dostring,
  393. .strategy = &sysctl_string,
  394. },
  395. #endif
  396. #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
  397. {
  398. .ctl_name = KERN_HOTPLUG,
  399. .procname = "hotplug",
  400. .data = &uevent_helper,
  401. .maxlen = UEVENT_HELPER_PATH_LEN,
  402. .mode = 0644,
  403. .proc_handler = &proc_dostring,
  404. .strategy = &sysctl_string,
  405. },
  406. #endif
  407. #ifdef CONFIG_CHR_DEV_SG
  408. {
  409. .ctl_name = KERN_SG_BIG_BUFF,
  410. .procname = "sg-big-buff",
  411. .data = &sg_big_buff,
  412. .maxlen = sizeof (int),
  413. .mode = 0444,
  414. .proc_handler = &proc_dointvec,
  415. },
  416. #endif
  417. #ifdef CONFIG_BSD_PROCESS_ACCT
  418. {
  419. .ctl_name = KERN_ACCT,
  420. .procname = "acct",
  421. .data = &acct_parm,
  422. .maxlen = 3*sizeof(int),
  423. .mode = 0644,
  424. .proc_handler = &proc_dointvec,
  425. },
  426. #endif
  427. #ifdef CONFIG_MAGIC_SYSRQ
  428. {
  429. .ctl_name = KERN_SYSRQ,
  430. .procname = "sysrq",
  431. .data = &__sysrq_enabled,
  432. .maxlen = sizeof (int),
  433. .mode = 0644,
  434. .proc_handler = &proc_dointvec,
  435. },
  436. #endif
  437. #ifdef CONFIG_PROC_SYSCTL
  438. {
  439. .ctl_name = KERN_CADPID,
  440. .procname = "cad_pid",
  441. .data = NULL,
  442. .maxlen = sizeof (int),
  443. .mode = 0600,
  444. .proc_handler = &proc_do_cad_pid,
  445. },
  446. #endif
  447. {
  448. .ctl_name = KERN_MAX_THREADS,
  449. .procname = "threads-max",
  450. .data = &max_threads,
  451. .maxlen = sizeof(int),
  452. .mode = 0644,
  453. .proc_handler = &proc_dointvec,
  454. },
  455. {
  456. .ctl_name = KERN_RANDOM,
  457. .procname = "random",
  458. .mode = 0555,
  459. .child = random_table,
  460. },
  461. #ifdef CONFIG_UNIX98_PTYS
  462. {
  463. .ctl_name = KERN_PTY,
  464. .procname = "pty",
  465. .mode = 0555,
  466. .child = pty_table,
  467. },
  468. #endif
  469. {
  470. .ctl_name = KERN_OVERFLOWUID,
  471. .procname = "overflowuid",
  472. .data = &overflowuid,
  473. .maxlen = sizeof(int),
  474. .mode = 0644,
  475. .proc_handler = &proc_dointvec_minmax,
  476. .strategy = &sysctl_intvec,
  477. .extra1 = &minolduid,
  478. .extra2 = &maxolduid,
  479. },
  480. {
  481. .ctl_name = KERN_OVERFLOWGID,
  482. .procname = "overflowgid",
  483. .data = &overflowgid,
  484. .maxlen = sizeof(int),
  485. .mode = 0644,
  486. .proc_handler = &proc_dointvec_minmax,
  487. .strategy = &sysctl_intvec,
  488. .extra1 = &minolduid,
  489. .extra2 = &maxolduid,
  490. },
  491. #ifdef CONFIG_S390
  492. #ifdef CONFIG_MATHEMU
  493. {
  494. .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
  495. .procname = "ieee_emulation_warnings",
  496. .data = &sysctl_ieee_emulation_warnings,
  497. .maxlen = sizeof(int),
  498. .mode = 0644,
  499. .proc_handler = &proc_dointvec,
  500. },
  501. #endif
  502. #ifdef CONFIG_NO_IDLE_HZ
  503. {
  504. .ctl_name = KERN_HZ_TIMER,
  505. .procname = "hz_timer",
  506. .data = &sysctl_hz_timer,
  507. .maxlen = sizeof(int),
  508. .mode = 0644,
  509. .proc_handler = &proc_dointvec,
  510. },
  511. #endif
  512. {
  513. .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
  514. .procname = "userprocess_debug",
  515. .data = &sysctl_userprocess_debug,
  516. .maxlen = sizeof(int),
  517. .mode = 0644,
  518. .proc_handler = &proc_dointvec,
  519. },
  520. #endif
  521. {
  522. .ctl_name = KERN_PIDMAX,
  523. .procname = "pid_max",
  524. .data = &pid_max,
  525. .maxlen = sizeof (int),
  526. .mode = 0644,
  527. .proc_handler = &proc_dointvec_minmax,
  528. .strategy = sysctl_intvec,
  529. .extra1 = &pid_max_min,
  530. .extra2 = &pid_max_max,
  531. },
  532. {
  533. .ctl_name = KERN_PANIC_ON_OOPS,
  534. .procname = "panic_on_oops",
  535. .data = &panic_on_oops,
  536. .maxlen = sizeof(int),
  537. .mode = 0644,
  538. .proc_handler = &proc_dointvec,
  539. },
  540. {
  541. .ctl_name = KERN_PRINTK_RATELIMIT,
  542. .procname = "printk_ratelimit",
  543. .data = &printk_ratelimit_jiffies,
  544. .maxlen = sizeof(int),
  545. .mode = 0644,
  546. .proc_handler = &proc_dointvec_jiffies,
  547. .strategy = &sysctl_jiffies,
  548. },
  549. {
  550. .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
  551. .procname = "printk_ratelimit_burst",
  552. .data = &printk_ratelimit_burst,
  553. .maxlen = sizeof(int),
  554. .mode = 0644,
  555. .proc_handler = &proc_dointvec,
  556. },
  557. {
  558. .ctl_name = KERN_NGROUPS_MAX,
  559. .procname = "ngroups_max",
  560. .data = &ngroups_max,
  561. .maxlen = sizeof (int),
  562. .mode = 0444,
  563. .proc_handler = &proc_dointvec,
  564. },
  565. #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
  566. {
  567. .ctl_name = KERN_UNKNOWN_NMI_PANIC,
  568. .procname = "unknown_nmi_panic",
  569. .data = &unknown_nmi_panic,
  570. .maxlen = sizeof (int),
  571. .mode = 0644,
  572. .proc_handler = &proc_dointvec,
  573. },
  574. {
  575. .ctl_name = KERN_NMI_WATCHDOG,
  576. .procname = "nmi_watchdog",
  577. .data = &nmi_watchdog_enabled,
  578. .maxlen = sizeof (int),
  579. .mode = 0644,
  580. .proc_handler = &proc_nmi_enabled,
  581. },
  582. #endif
  583. #if defined(CONFIG_X86)
  584. {
  585. .ctl_name = KERN_PANIC_ON_NMI,
  586. .procname = "panic_on_unrecovered_nmi",
  587. .data = &panic_on_unrecovered_nmi,
  588. .maxlen = sizeof(int),
  589. .mode = 0644,
  590. .proc_handler = &proc_dointvec,
  591. },
  592. {
  593. .ctl_name = KERN_BOOTLOADER_TYPE,
  594. .procname = "bootloader_type",
  595. .data = &bootloader_type,
  596. .maxlen = sizeof (int),
  597. .mode = 0444,
  598. .proc_handler = &proc_dointvec,
  599. },
  600. {
  601. .ctl_name = CTL_UNNUMBERED,
  602. .procname = "kstack_depth_to_print",
  603. .data = &kstack_depth_to_print,
  604. .maxlen = sizeof(int),
  605. .mode = 0644,
  606. .proc_handler = &proc_dointvec,
  607. },
  608. #endif
  609. #if defined(CONFIG_MMU)
  610. {
  611. .ctl_name = KERN_RANDOMIZE,
  612. .procname = "randomize_va_space",
  613. .data = &randomize_va_space,
  614. .maxlen = sizeof(int),
  615. .mode = 0644,
  616. .proc_handler = &proc_dointvec,
  617. },
  618. #endif
  619. #if defined(CONFIG_S390) && defined(CONFIG_SMP)
  620. {
  621. .ctl_name = KERN_SPIN_RETRY,
  622. .procname = "spin_retry",
  623. .data = &spin_retry,
  624. .maxlen = sizeof (int),
  625. .mode = 0644,
  626. .proc_handler = &proc_dointvec,
  627. },
  628. #endif
  629. #ifdef CONFIG_ACPI_SLEEP
  630. {
  631. .ctl_name = KERN_ACPI_VIDEO_FLAGS,
  632. .procname = "acpi_video_flags",
  633. .data = &acpi_video_flags,
  634. .maxlen = sizeof (unsigned long),
  635. .mode = 0644,
  636. .proc_handler = &proc_doulongvec_minmax,
  637. },
  638. #endif
  639. #ifdef CONFIG_IA64
  640. {
  641. .ctl_name = KERN_IA64_UNALIGNED,
  642. .procname = "ignore-unaligned-usertrap",
  643. .data = &no_unaligned_warning,
  644. .maxlen = sizeof (int),
  645. .mode = 0644,
  646. .proc_handler = &proc_dointvec,
  647. },
  648. #endif
  649. #ifdef CONFIG_COMPAT
  650. {
  651. .ctl_name = KERN_COMPAT_LOG,
  652. .procname = "compat-log",
  653. .data = &compat_log,
  654. .maxlen = sizeof (int),
  655. .mode = 0644,
  656. .proc_handler = &proc_dointvec,
  657. },
  658. #endif
  659. #ifdef CONFIG_RT_MUTEXES
  660. {
  661. .ctl_name = KERN_MAX_LOCK_DEPTH,
  662. .procname = "max_lock_depth",
  663. .data = &max_lock_depth,
  664. .maxlen = sizeof(int),
  665. .mode = 0644,
  666. .proc_handler = &proc_dointvec,
  667. },
  668. #endif
  669. #ifdef CONFIG_PROC_FS
  670. {
  671. .ctl_name = CTL_UNNUMBERED,
  672. .procname = "maps_protect",
  673. .data = &maps_protect,
  674. .maxlen = sizeof(int),
  675. .mode = 0644,
  676. .proc_handler = &proc_dointvec,
  677. },
  678. #endif
  679. { .ctl_name = 0 }
  680. };
  681. /* Constants for minimum and maximum testing in vm_table.
  682. We use these as one-element integer vectors. */
  683. static int zero;
  684. static int one_hundred = 100;
  685. static ctl_table vm_table[] = {
  686. {
  687. .ctl_name = VM_OVERCOMMIT_MEMORY,
  688. .procname = "overcommit_memory",
  689. .data = &sysctl_overcommit_memory,
  690. .maxlen = sizeof(sysctl_overcommit_memory),
  691. .mode = 0644,
  692. .proc_handler = &proc_dointvec,
  693. },
  694. {
  695. .ctl_name = VM_PANIC_ON_OOM,
  696. .procname = "panic_on_oom",
  697. .data = &sysctl_panic_on_oom,
  698. .maxlen = sizeof(sysctl_panic_on_oom),
  699. .mode = 0644,
  700. .proc_handler = &proc_dointvec,
  701. },
  702. {
  703. .ctl_name = VM_OVERCOMMIT_RATIO,
  704. .procname = "overcommit_ratio",
  705. .data = &sysctl_overcommit_ratio,
  706. .maxlen = sizeof(sysctl_overcommit_ratio),
  707. .mode = 0644,
  708. .proc_handler = &proc_dointvec,
  709. },
  710. {
  711. .ctl_name = VM_PAGE_CLUSTER,
  712. .procname = "page-cluster",
  713. .data = &page_cluster,
  714. .maxlen = sizeof(int),
  715. .mode = 0644,
  716. .proc_handler = &proc_dointvec,
  717. },
  718. {
  719. .ctl_name = VM_DIRTY_BACKGROUND,
  720. .procname = "dirty_background_ratio",
  721. .data = &dirty_background_ratio,
  722. .maxlen = sizeof(dirty_background_ratio),
  723. .mode = 0644,
  724. .proc_handler = &proc_dointvec_minmax,
  725. .strategy = &sysctl_intvec,
  726. .extra1 = &zero,
  727. .extra2 = &one_hundred,
  728. },
  729. {
  730. .ctl_name = VM_DIRTY_RATIO,
  731. .procname = "dirty_ratio",
  732. .data = &vm_dirty_ratio,
  733. .maxlen = sizeof(vm_dirty_ratio),
  734. .mode = 0644,
  735. .proc_handler = &proc_dointvec_minmax,
  736. .strategy = &sysctl_intvec,
  737. .extra1 = &zero,
  738. .extra2 = &one_hundred,
  739. },
  740. {
  741. .ctl_name = VM_DIRTY_WB_CS,
  742. .procname = "dirty_writeback_centisecs",
  743. .data = &dirty_writeback_interval,
  744. .maxlen = sizeof(dirty_writeback_interval),
  745. .mode = 0644,
  746. .proc_handler = &dirty_writeback_centisecs_handler,
  747. },
  748. {
  749. .ctl_name = VM_DIRTY_EXPIRE_CS,
  750. .procname = "dirty_expire_centisecs",
  751. .data = &dirty_expire_interval,
  752. .maxlen = sizeof(dirty_expire_interval),
  753. .mode = 0644,
  754. .proc_handler = &proc_dointvec_userhz_jiffies,
  755. },
  756. {
  757. .ctl_name = VM_NR_PDFLUSH_THREADS,
  758. .procname = "nr_pdflush_threads",
  759. .data = &nr_pdflush_threads,
  760. .maxlen = sizeof nr_pdflush_threads,
  761. .mode = 0444 /* read-only*/,
  762. .proc_handler = &proc_dointvec,
  763. },
  764. {
  765. .ctl_name = VM_SWAPPINESS,
  766. .procname = "swappiness",
  767. .data = &vm_swappiness,
  768. .maxlen = sizeof(vm_swappiness),
  769. .mode = 0644,
  770. .proc_handler = &proc_dointvec_minmax,
  771. .strategy = &sysctl_intvec,
  772. .extra1 = &zero,
  773. .extra2 = &one_hundred,
  774. },
  775. #ifdef CONFIG_HUGETLB_PAGE
  776. {
  777. .ctl_name = VM_HUGETLB_PAGES,
  778. .procname = "nr_hugepages",
  779. .data = &max_huge_pages,
  780. .maxlen = sizeof(unsigned long),
  781. .mode = 0644,
  782. .proc_handler = &hugetlb_sysctl_handler,
  783. .extra1 = (void *)&hugetlb_zero,
  784. .extra2 = (void *)&hugetlb_infinity,
  785. },
  786. {
  787. .ctl_name = VM_HUGETLB_GROUP,
  788. .procname = "hugetlb_shm_group",
  789. .data = &sysctl_hugetlb_shm_group,
  790. .maxlen = sizeof(gid_t),
  791. .mode = 0644,
  792. .proc_handler = &proc_dointvec,
  793. },
  794. #endif
  795. {
  796. .ctl_name = VM_LOWMEM_RESERVE_RATIO,
  797. .procname = "lowmem_reserve_ratio",
  798. .data = &sysctl_lowmem_reserve_ratio,
  799. .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
  800. .mode = 0644,
  801. .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
  802. .strategy = &sysctl_intvec,
  803. },
  804. {
  805. .ctl_name = VM_DROP_PAGECACHE,
  806. .procname = "drop_caches",
  807. .data = &sysctl_drop_caches,
  808. .maxlen = sizeof(int),
  809. .mode = 0644,
  810. .proc_handler = drop_caches_sysctl_handler,
  811. .strategy = &sysctl_intvec,
  812. },
  813. {
  814. .ctl_name = VM_MIN_FREE_KBYTES,
  815. .procname = "min_free_kbytes",
  816. .data = &min_free_kbytes,
  817. .maxlen = sizeof(min_free_kbytes),
  818. .mode = 0644,
  819. .proc_handler = &min_free_kbytes_sysctl_handler,
  820. .strategy = &sysctl_intvec,
  821. .extra1 = &zero,
  822. },
  823. {
  824. .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
  825. .procname = "percpu_pagelist_fraction",
  826. .data = &percpu_pagelist_fraction,
  827. .maxlen = sizeof(percpu_pagelist_fraction),
  828. .mode = 0644,
  829. .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
  830. .strategy = &sysctl_intvec,
  831. .extra1 = &min_percpu_pagelist_fract,
  832. },
  833. #ifdef CONFIG_MMU
  834. {
  835. .ctl_name = VM_MAX_MAP_COUNT,
  836. .procname = "max_map_count",
  837. .data = &sysctl_max_map_count,
  838. .maxlen = sizeof(sysctl_max_map_count),
  839. .mode = 0644,
  840. .proc_handler = &proc_dointvec
  841. },
  842. #endif
  843. {
  844. .ctl_name = VM_LAPTOP_MODE,
  845. .procname = "laptop_mode",
  846. .data = &laptop_mode,
  847. .maxlen = sizeof(laptop_mode),
  848. .mode = 0644,
  849. .proc_handler = &proc_dointvec_jiffies,
  850. .strategy = &sysctl_jiffies,
  851. },
  852. {
  853. .ctl_name = VM_BLOCK_DUMP,
  854. .procname = "block_dump",
  855. .data = &block_dump,
  856. .maxlen = sizeof(block_dump),
  857. .mode = 0644,
  858. .proc_handler = &proc_dointvec,
  859. .strategy = &sysctl_intvec,
  860. .extra1 = &zero,
  861. },
  862. {
  863. .ctl_name = VM_VFS_CACHE_PRESSURE,
  864. .procname = "vfs_cache_pressure",
  865. .data = &sysctl_vfs_cache_pressure,
  866. .maxlen = sizeof(sysctl_vfs_cache_pressure),
  867. .mode = 0644,
  868. .proc_handler = &proc_dointvec,
  869. .strategy = &sysctl_intvec,
  870. .extra1 = &zero,
  871. },
  872. #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
  873. {
  874. .ctl_name = VM_LEGACY_VA_LAYOUT,
  875. .procname = "legacy_va_layout",
  876. .data = &sysctl_legacy_va_layout,
  877. .maxlen = sizeof(sysctl_legacy_va_layout),
  878. .mode = 0644,
  879. .proc_handler = &proc_dointvec,
  880. .strategy = &sysctl_intvec,
  881. .extra1 = &zero,
  882. },
  883. #endif
  884. #ifdef CONFIG_NUMA
  885. {
  886. .ctl_name = VM_ZONE_RECLAIM_MODE,
  887. .procname = "zone_reclaim_mode",
  888. .data = &zone_reclaim_mode,
  889. .maxlen = sizeof(zone_reclaim_mode),
  890. .mode = 0644,
  891. .proc_handler = &proc_dointvec,
  892. .strategy = &sysctl_intvec,
  893. .extra1 = &zero,
  894. },
  895. {
  896. .ctl_name = VM_MIN_UNMAPPED,
  897. .procname = "min_unmapped_ratio",
  898. .data = &sysctl_min_unmapped_ratio,
  899. .maxlen = sizeof(sysctl_min_unmapped_ratio),
  900. .mode = 0644,
  901. .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
  902. .strategy = &sysctl_intvec,
  903. .extra1 = &zero,
  904. .extra2 = &one_hundred,
  905. },
  906. {
  907. .ctl_name = VM_MIN_SLAB,
  908. .procname = "min_slab_ratio",
  909. .data = &sysctl_min_slab_ratio,
  910. .maxlen = sizeof(sysctl_min_slab_ratio),
  911. .mode = 0644,
  912. .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
  913. .strategy = &sysctl_intvec,
  914. .extra1 = &zero,
  915. .extra2 = &one_hundred,
  916. },
  917. #endif
  918. #ifdef CONFIG_SMP
  919. {
  920. .ctl_name = CTL_UNNUMBERED,
  921. .procname = "stat_interval",
  922. .data = &sysctl_stat_interval,
  923. .maxlen = sizeof(sysctl_stat_interval),
  924. .mode = 0644,
  925. .proc_handler = &proc_dointvec_jiffies,
  926. .strategy = &sysctl_jiffies,
  927. },
  928. #endif
  929. #ifdef CONFIG_SECURITY
  930. {
  931. .ctl_name = CTL_UNNUMBERED,
  932. .procname = "mmap_min_addr",
  933. .data = &mmap_min_addr,
  934. .maxlen = sizeof(unsigned long),
  935. .mode = 0644,
  936. .proc_handler = &proc_doulongvec_minmax,
  937. },
  938. #ifdef CONFIG_NUMA
  939. {
  940. .ctl_name = CTL_UNNUMBERED,
  941. .procname = "numa_zonelist_order",
  942. .data = &numa_zonelist_order,
  943. .maxlen = NUMA_ZONELIST_ORDER_LEN,
  944. .mode = 0644,
  945. .proc_handler = &numa_zonelist_order_handler,
  946. .strategy = &sysctl_string,
  947. },
  948. #endif
  949. #endif
  950. #if defined(CONFIG_X86_32) || \
  951. (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
  952. {
  953. .ctl_name = VM_VDSO_ENABLED,
  954. .procname = "vdso_enabled",
  955. .data = &vdso_enabled,
  956. .maxlen = sizeof(vdso_enabled),
  957. .mode = 0644,
  958. .proc_handler = &proc_dointvec,
  959. .strategy = &sysctl_intvec,
  960. .extra1 = &zero,
  961. },
  962. #endif
  963. { .ctl_name = 0 }
  964. };
  965. #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
  966. static ctl_table binfmt_misc_table[] = {
  967. { .ctl_name = 0 }
  968. };
  969. #endif
  970. static ctl_table fs_table[] = {
  971. {
  972. .ctl_name = FS_NRINODE,
  973. .procname = "inode-nr",
  974. .data = &inodes_stat,
  975. .maxlen = 2*sizeof(int),
  976. .mode = 0444,
  977. .proc_handler = &proc_dointvec,
  978. },
  979. {
  980. .ctl_name = FS_STATINODE,
  981. .procname = "inode-state",
  982. .data = &inodes_stat,
  983. .maxlen = 7*sizeof(int),
  984. .mode = 0444,
  985. .proc_handler = &proc_dointvec,
  986. },
  987. {
  988. .ctl_name = FS_NRFILE,
  989. .procname = "file-nr",
  990. .data = &files_stat,
  991. .maxlen = 3*sizeof(int),
  992. .mode = 0444,
  993. .proc_handler = &proc_nr_files,
  994. },
  995. {
  996. .ctl_name = FS_MAXFILE,
  997. .procname = "file-max",
  998. .data = &files_stat.max_files,
  999. .maxlen = sizeof(int),
  1000. .mode = 0644,
  1001. .proc_handler = &proc_dointvec,
  1002. },
  1003. {
  1004. .ctl_name = FS_DENTRY,
  1005. .procname = "dentry-state",
  1006. .data = &dentry_stat,
  1007. .maxlen = 6*sizeof(int),
  1008. .mode = 0444,
  1009. .proc_handler = &proc_dointvec,
  1010. },
  1011. {
  1012. .ctl_name = FS_OVERFLOWUID,
  1013. .procname = "overflowuid",
  1014. .data = &fs_overflowuid,
  1015. .maxlen = sizeof(int),
  1016. .mode = 0644,
  1017. .proc_handler = &proc_dointvec_minmax,
  1018. .strategy = &sysctl_intvec,
  1019. .extra1 = &minolduid,
  1020. .extra2 = &maxolduid,
  1021. },
  1022. {
  1023. .ctl_name = FS_OVERFLOWGID,
  1024. .procname = "overflowgid",
  1025. .data = &fs_overflowgid,
  1026. .maxlen = sizeof(int),
  1027. .mode = 0644,
  1028. .proc_handler = &proc_dointvec_minmax,
  1029. .strategy = &sysctl_intvec,
  1030. .extra1 = &minolduid,
  1031. .extra2 = &maxolduid,
  1032. },
  1033. {
  1034. .ctl_name = FS_LEASES,
  1035. .procname = "leases-enable",
  1036. .data = &leases_enable,
  1037. .maxlen = sizeof(int),
  1038. .mode = 0644,
  1039. .proc_handler = &proc_dointvec,
  1040. },
  1041. #ifdef CONFIG_DNOTIFY
  1042. {
  1043. .ctl_name = FS_DIR_NOTIFY,
  1044. .procname = "dir-notify-enable",
  1045. .data = &dir_notify_enable,
  1046. .maxlen = sizeof(int),
  1047. .mode = 0644,
  1048. .proc_handler = &proc_dointvec,
  1049. },
  1050. #endif
  1051. #ifdef CONFIG_MMU
  1052. {
  1053. .ctl_name = FS_LEASE_TIME,
  1054. .procname = "lease-break-time",
  1055. .data = &lease_break_time,
  1056. .maxlen = sizeof(int),
  1057. .mode = 0644,
  1058. .proc_handler = &proc_dointvec,
  1059. },
  1060. {
  1061. .ctl_name = FS_AIO_NR,
  1062. .procname = "aio-nr",
  1063. .data = &aio_nr,
  1064. .maxlen = sizeof(aio_nr),
  1065. .mode = 0444,
  1066. .proc_handler = &proc_doulongvec_minmax,
  1067. },
  1068. {
  1069. .ctl_name = FS_AIO_MAX_NR,
  1070. .procname = "aio-max-nr",
  1071. .data = &aio_max_nr,
  1072. .maxlen = sizeof(aio_max_nr),
  1073. .mode = 0644,
  1074. .proc_handler = &proc_doulongvec_minmax,
  1075. },
  1076. #ifdef CONFIG_INOTIFY_USER
  1077. {
  1078. .ctl_name = FS_INOTIFY,
  1079. .procname = "inotify",
  1080. .mode = 0555,
  1081. .child = inotify_table,
  1082. },
  1083. #endif
  1084. #endif
  1085. {
  1086. .ctl_name = KERN_SETUID_DUMPABLE,
  1087. .procname = "suid_dumpable",
  1088. .data = &suid_dumpable,
  1089. .maxlen = sizeof(int),
  1090. .mode = 0644,
  1091. .proc_handler = &proc_dointvec,
  1092. },
  1093. #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
  1094. {
  1095. .ctl_name = CTL_UNNUMBERED,
  1096. .procname = "binfmt_misc",
  1097. .mode = 0555,
  1098. .child = binfmt_misc_table,
  1099. },
  1100. #endif
  1101. { .ctl_name = 0 }
  1102. };
  1103. static ctl_table debug_table[] = {
  1104. { .ctl_name = 0 }
  1105. };
  1106. static ctl_table dev_table[] = {
  1107. { .ctl_name = 0 }
  1108. };
  1109. static DEFINE_SPINLOCK(sysctl_lock);
  1110. /* called under sysctl_lock */
  1111. static int use_table(struct ctl_table_header *p)
  1112. {
  1113. if (unlikely(p->unregistering))
  1114. return 0;
  1115. p->used++;
  1116. return 1;
  1117. }
  1118. /* called under sysctl_lock */
  1119. static void unuse_table(struct ctl_table_header *p)
  1120. {
  1121. if (!--p->used)
  1122. if (unlikely(p->unregistering))
  1123. complete(p->unregistering);
  1124. }
  1125. /* called under sysctl_lock, will reacquire if has to wait */
  1126. static void start_unregistering(struct ctl_table_header *p)
  1127. {
  1128. /*
  1129. * if p->used is 0, nobody will ever touch that entry again;
  1130. * we'll eliminate all paths to it before dropping sysctl_lock
  1131. */
  1132. if (unlikely(p->used)) {
  1133. struct completion wait;
  1134. init_completion(&wait);
  1135. p->unregistering = &wait;
  1136. spin_unlock(&sysctl_lock);
  1137. wait_for_completion(&wait);
  1138. spin_lock(&sysctl_lock);
  1139. }
  1140. /*
  1141. * do not remove from the list until nobody holds it; walking the
  1142. * list in do_sysctl() relies on that.
  1143. */
  1144. list_del_init(&p->ctl_entry);
  1145. }
  1146. void sysctl_head_finish(struct ctl_table_header *head)
  1147. {
  1148. if (!head)
  1149. return;
  1150. spin_lock(&sysctl_lock);
  1151. unuse_table(head);
  1152. spin_unlock(&sysctl_lock);
  1153. }
  1154. struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
  1155. {
  1156. struct ctl_table_header *head;
  1157. struct list_head *tmp;
  1158. spin_lock(&sysctl_lock);
  1159. if (prev) {
  1160. tmp = &prev->ctl_entry;
  1161. unuse_table(prev);
  1162. goto next;
  1163. }
  1164. tmp = &root_table_header.ctl_entry;
  1165. for (;;) {
  1166. head = list_entry(tmp, struct ctl_table_header, ctl_entry);
  1167. if (!use_table(head))
  1168. goto next;
  1169. spin_unlock(&sysctl_lock);
  1170. return head;
  1171. next:
  1172. tmp = tmp->next;
  1173. if (tmp == &root_table_header.ctl_entry)
  1174. break;
  1175. }
  1176. spin_unlock(&sysctl_lock);
  1177. return NULL;
  1178. }
  1179. #ifdef CONFIG_SYSCTL_SYSCALL
  1180. int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
  1181. void __user *newval, size_t newlen)
  1182. {
  1183. struct ctl_table_header *head;
  1184. int error = -ENOTDIR;
  1185. if (nlen <= 0 || nlen >= CTL_MAXNAME)
  1186. return -ENOTDIR;
  1187. if (oldval) {
  1188. int old_len;
  1189. if (!oldlenp || get_user(old_len, oldlenp))
  1190. return -EFAULT;
  1191. }
  1192. for (head = sysctl_head_next(NULL); head;
  1193. head = sysctl_head_next(head)) {
  1194. error = parse_table(name, nlen, oldval, oldlenp,
  1195. newval, newlen, head->ctl_table);
  1196. if (error != -ENOTDIR) {
  1197. sysctl_head_finish(head);
  1198. break;
  1199. }
  1200. }
  1201. return error;
  1202. }
  1203. asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
  1204. {
  1205. struct __sysctl_args tmp;
  1206. int error;
  1207. if (copy_from_user(&tmp, args, sizeof(tmp)))
  1208. return -EFAULT;
  1209. lock_kernel();
  1210. error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
  1211. tmp.newval, tmp.newlen);
  1212. unlock_kernel();
  1213. return error;
  1214. }
  1215. #endif /* CONFIG_SYSCTL_SYSCALL */
  1216. /*
  1217. * sysctl_perm does NOT grant the superuser all rights automatically, because
  1218. * some sysctl variables are readonly even to root.
  1219. */
  1220. static int test_perm(int mode, int op)
  1221. {
  1222. if (!current->euid)
  1223. mode >>= 6;
  1224. else if (in_egroup_p(0))
  1225. mode >>= 3;
  1226. if ((mode & op & 0007) == op)
  1227. return 0;
  1228. return -EACCES;
  1229. }
  1230. int sysctl_perm(ctl_table *table, int op)
  1231. {
  1232. int error;
  1233. error = security_sysctl(table, op);
  1234. if (error)
  1235. return error;
  1236. return test_perm(table->mode, op);
  1237. }
  1238. #ifdef CONFIG_SYSCTL_SYSCALL
  1239. static int parse_table(int __user *name, int nlen,
  1240. void __user *oldval, size_t __user *oldlenp,
  1241. void __user *newval, size_t newlen,
  1242. ctl_table *table)
  1243. {
  1244. int n;
  1245. repeat:
  1246. if (!nlen)
  1247. return -ENOTDIR;
  1248. if (get_user(n, name))
  1249. return -EFAULT;
  1250. for ( ; table->ctl_name || table->procname; table++) {
  1251. if (!table->ctl_name)
  1252. continue;
  1253. if (n == table->ctl_name) {
  1254. int error;
  1255. if (table->child) {
  1256. if (sysctl_perm(table, 001))
  1257. return -EPERM;
  1258. name++;
  1259. nlen--;
  1260. table = table->child;
  1261. goto repeat;
  1262. }
  1263. error = do_sysctl_strategy(table, name, nlen,
  1264. oldval, oldlenp,
  1265. newval, newlen);
  1266. return error;
  1267. }
  1268. }
  1269. return -ENOTDIR;
  1270. }
  1271. /* Perform the actual read/write of a sysctl table entry. */
  1272. int do_sysctl_strategy (ctl_table *table,
  1273. int __user *name, int nlen,
  1274. void __user *oldval, size_t __user *oldlenp,
  1275. void __user *newval, size_t newlen)
  1276. {
  1277. int op = 0, rc;
  1278. size_t len;
  1279. if (oldval)
  1280. op |= 004;
  1281. if (newval)
  1282. op |= 002;
  1283. if (sysctl_perm(table, op))
  1284. return -EPERM;
  1285. if (table->strategy) {
  1286. rc = table->strategy(table, name, nlen, oldval, oldlenp,
  1287. newval, newlen);
  1288. if (rc < 0)
  1289. return rc;
  1290. if (rc > 0)
  1291. return 0;
  1292. }
  1293. /* If there is no strategy routine, or if the strategy returns
  1294. * zero, proceed with automatic r/w */
  1295. if (table->data && table->maxlen) {
  1296. if (oldval && oldlenp) {
  1297. if (get_user(len, oldlenp))
  1298. return -EFAULT;
  1299. if (len) {
  1300. if (len > table->maxlen)
  1301. len = table->maxlen;
  1302. if(copy_to_user(oldval, table->data, len))
  1303. return -EFAULT;
  1304. if(put_user(len, oldlenp))
  1305. return -EFAULT;
  1306. }
  1307. }
  1308. if (newval && newlen) {
  1309. len = newlen;
  1310. if (len > table->maxlen)
  1311. len = table->maxlen;
  1312. if(copy_from_user(table->data, newval, len))
  1313. return -EFAULT;
  1314. }
  1315. }
  1316. return 0;
  1317. }
  1318. #endif /* CONFIG_SYSCTL_SYSCALL */
  1319. static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
  1320. {
  1321. for (; table->ctl_name || table->procname; table++) {
  1322. table->parent = parent;
  1323. if (table->child)
  1324. sysctl_set_parent(table, table->child);
  1325. }
  1326. }
  1327. static __init int sysctl_init(void)
  1328. {
  1329. sysctl_set_parent(NULL, root_table);
  1330. return 0;
  1331. }
  1332. core_initcall(sysctl_init);
  1333. /**
  1334. * register_sysctl_table - register a sysctl hierarchy
  1335. * @table: the top-level table structure
  1336. *
  1337. * Register a sysctl table hierarchy. @table should be a filled in ctl_table
  1338. * array. An entry with a ctl_name of 0 terminates the table.
  1339. *
  1340. * The members of the &ctl_table structure are used as follows:
  1341. *
  1342. * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
  1343. * must be unique within that level of sysctl
  1344. *
  1345. * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
  1346. * enter a sysctl file
  1347. *
  1348. * data - a pointer to data for use by proc_handler
  1349. *
  1350. * maxlen - the maximum size in bytes of the data
  1351. *
  1352. * mode - the file permissions for the /proc/sys file, and for sysctl(2)
  1353. *
  1354. * child - a pointer to the child sysctl table if this entry is a directory, or
  1355. * %NULL.
  1356. *
  1357. * proc_handler - the text handler routine (described below)
  1358. *
  1359. * strategy - the strategy routine (described below)
  1360. *
  1361. * de - for internal use by the sysctl routines
  1362. *
  1363. * extra1, extra2 - extra pointers usable by the proc handler routines
  1364. *
  1365. * Leaf nodes in the sysctl tree will be represented by a single file
  1366. * under /proc; non-leaf nodes will be represented by directories.
  1367. *
  1368. * sysctl(2) can automatically manage read and write requests through
  1369. * the sysctl table. The data and maxlen fields of the ctl_table
  1370. * struct enable minimal validation of the values being written to be
  1371. * performed, and the mode field allows minimal authentication.
  1372. *
  1373. * More sophisticated management can be enabled by the provision of a
  1374. * strategy routine with the table entry. This will be called before
  1375. * any automatic read or write of the data is performed.
  1376. *
  1377. * The strategy routine may return
  1378. *
  1379. * < 0 - Error occurred (error is passed to user process)
  1380. *
  1381. * 0 - OK - proceed with automatic read or write.
  1382. *
  1383. * > 0 - OK - read or write has been done by the strategy routine, so
  1384. * return immediately.
  1385. *
  1386. * There must be a proc_handler routine for any terminal nodes
  1387. * mirrored under /proc/sys (non-terminals are handled by a built-in
  1388. * directory handler). Several default handlers are available to
  1389. * cover common cases -
  1390. *
  1391. * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
  1392. * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
  1393. * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
  1394. *
  1395. * It is the handler's job to read the input buffer from user memory
  1396. * and process it. The handler should return 0 on success.
  1397. *
  1398. * This routine returns %NULL on a failure to register, and a pointer
  1399. * to the table header on success.
  1400. */
  1401. struct ctl_table_header *register_sysctl_table(ctl_table * table)
  1402. {
  1403. struct ctl_table_header *tmp;
  1404. tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
  1405. if (!tmp)
  1406. return NULL;
  1407. tmp->ctl_table = table;
  1408. INIT_LIST_HEAD(&tmp->ctl_entry);
  1409. tmp->used = 0;
  1410. tmp->unregistering = NULL;
  1411. sysctl_set_parent(NULL, table);
  1412. spin_lock(&sysctl_lock);
  1413. list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
  1414. spin_unlock(&sysctl_lock);
  1415. return tmp;
  1416. }
  1417. /**
  1418. * unregister_sysctl_table - unregister a sysctl table hierarchy
  1419. * @header: the header returned from register_sysctl_table
  1420. *
  1421. * Unregisters the sysctl table and all children. proc entries may not
  1422. * actually be removed until they are no longer used by anyone.
  1423. */
  1424. void unregister_sysctl_table(struct ctl_table_header * header)
  1425. {
  1426. might_sleep();
  1427. spin_lock(&sysctl_lock);
  1428. start_unregistering(header);
  1429. spin_unlock(&sysctl_lock);
  1430. kfree(header);
  1431. }
  1432. #else /* !CONFIG_SYSCTL */
  1433. struct ctl_table_header *register_sysctl_table(ctl_table * table)
  1434. {
  1435. return NULL;
  1436. }
  1437. void unregister_sysctl_table(struct ctl_table_header * table)
  1438. {
  1439. }
  1440. #endif /* CONFIG_SYSCTL */
  1441. /*
  1442. * /proc/sys support
  1443. */
  1444. #ifdef CONFIG_PROC_SYSCTL
  1445. static int _proc_do_string(void* data, int maxlen, int write,
  1446. struct file *filp, void __user *buffer,
  1447. size_t *lenp, loff_t *ppos)
  1448. {
  1449. size_t len;
  1450. char __user *p;
  1451. char c;
  1452. if (!data || !maxlen || !*lenp) {
  1453. *lenp = 0;
  1454. return 0;
  1455. }
  1456. if (write) {
  1457. len = 0;
  1458. p = buffer;
  1459. while (len < *lenp) {
  1460. if (get_user(c, p++))
  1461. return -EFAULT;
  1462. if (c == 0 || c == '\n')
  1463. break;
  1464. len++;
  1465. }
  1466. if (len >= maxlen)
  1467. len = maxlen-1;
  1468. if(copy_from_user(data, buffer, len))
  1469. return -EFAULT;
  1470. ((char *) data)[len] = 0;
  1471. *ppos += *lenp;
  1472. } else {
  1473. len = strlen(data);
  1474. if (len > maxlen)
  1475. len = maxlen;
  1476. if (*ppos > len) {
  1477. *lenp = 0;
  1478. return 0;
  1479. }
  1480. data += *ppos;
  1481. len -= *ppos;
  1482. if (len > *lenp)
  1483. len = *lenp;
  1484. if (len)
  1485. if(copy_to_user(buffer, data, len))
  1486. return -EFAULT;
  1487. if (len < *lenp) {
  1488. if(put_user('\n', ((char __user *) buffer) + len))
  1489. return -EFAULT;
  1490. len++;
  1491. }
  1492. *lenp = len;
  1493. *ppos += len;
  1494. }
  1495. return 0;
  1496. }
  1497. /**
  1498. * proc_dostring - read a string sysctl
  1499. * @table: the sysctl table
  1500. * @write: %TRUE if this is a write to the sysctl file
  1501. * @filp: the file structure
  1502. * @buffer: the user buffer
  1503. * @lenp: the size of the user buffer
  1504. * @ppos: file position
  1505. *
  1506. * Reads/writes a string from/to the user buffer. If the kernel
  1507. * buffer provided is not large enough to hold the string, the
  1508. * string is truncated. The copied string is %NULL-terminated.
  1509. * If the string is being read by the user process, it is copied
  1510. * and a newline '\n' is added. It is truncated if the buffer is
  1511. * not large enough.
  1512. *
  1513. * Returns 0 on success.
  1514. */
  1515. int proc_dostring(ctl_table *table, int write, struct file *filp,
  1516. void __user *buffer, size_t *lenp, loff_t *ppos)
  1517. {
  1518. return _proc_do_string(table->data, table->maxlen, write, filp,
  1519. buffer, lenp, ppos);
  1520. }
  1521. static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
  1522. int *valp,
  1523. int write, void *data)
  1524. {
  1525. if (write) {
  1526. *valp = *negp ? -*lvalp : *lvalp;
  1527. } else {
  1528. int val = *valp;
  1529. if (val < 0) {
  1530. *negp = -1;
  1531. *lvalp = (unsigned long)-val;
  1532. } else {
  1533. *negp = 0;
  1534. *lvalp = (unsigned long)val;
  1535. }
  1536. }
  1537. return 0;
  1538. }
  1539. static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
  1540. int write, struct file *filp, void __user *buffer,
  1541. size_t *lenp, loff_t *ppos,
  1542. int (*conv)(int *negp, unsigned long *lvalp, int *valp,
  1543. int write, void *data),
  1544. void *data)
  1545. {
  1546. #define TMPBUFLEN 21
  1547. int *i, vleft, first=1, neg, val;
  1548. unsigned long lval;
  1549. size_t left, len;
  1550. char buf[TMPBUFLEN], *p;
  1551. char __user *s = buffer;
  1552. if (!tbl_data || !table->maxlen || !*lenp ||
  1553. (*ppos && !write)) {
  1554. *lenp = 0;
  1555. return 0;
  1556. }
  1557. i = (int *) tbl_data;
  1558. vleft = table->maxlen / sizeof(*i);
  1559. left = *lenp;
  1560. if (!conv)
  1561. conv = do_proc_dointvec_conv;
  1562. for (; left && vleft--; i++, first=0) {
  1563. if (write) {
  1564. while (left) {
  1565. char c;
  1566. if (get_user(c, s))
  1567. return -EFAULT;
  1568. if (!isspace(c))
  1569. break;
  1570. left--;
  1571. s++;
  1572. }
  1573. if (!left)
  1574. break;
  1575. neg = 0;
  1576. len = left;
  1577. if (len > sizeof(buf) - 1)
  1578. len = sizeof(buf) - 1;
  1579. if (copy_from_user(buf, s, len))
  1580. return -EFAULT;
  1581. buf[len] = 0;
  1582. p = buf;
  1583. if (*p == '-' && left > 1) {
  1584. neg = 1;
  1585. p++;
  1586. }
  1587. if (*p < '0' || *p > '9')
  1588. break;
  1589. lval = simple_strtoul(p, &p, 0);
  1590. len = p-buf;
  1591. if ((len < left) && *p && !isspace(*p))
  1592. break;
  1593. if (neg)
  1594. val = -val;
  1595. s += len;
  1596. left -= len;
  1597. if (conv(&neg, &lval, i, 1, data))
  1598. break;
  1599. } else {
  1600. p = buf;
  1601. if (!first)
  1602. *p++ = '\t';
  1603. if (conv(&neg, &lval, i, 0, data))
  1604. break;
  1605. sprintf(p, "%s%lu", neg ? "-" : "", lval);
  1606. len = strlen(buf);
  1607. if (len > left)
  1608. len = left;
  1609. if(copy_to_user(s, buf, len))
  1610. return -EFAULT;
  1611. left -= len;
  1612. s += len;
  1613. }
  1614. }
  1615. if (!write && !first && left) {
  1616. if(put_user('\n', s))
  1617. return -EFAULT;
  1618. left--, s++;
  1619. }
  1620. if (write) {
  1621. while (left) {
  1622. char c;
  1623. if (get_user(c, s++))
  1624. return -EFAULT;
  1625. if (!isspace(c))
  1626. break;
  1627. left--;
  1628. }
  1629. }
  1630. if (write && first)
  1631. return -EINVAL;
  1632. *lenp -= left;
  1633. *ppos += *lenp;
  1634. return 0;
  1635. #undef TMPBUFLEN
  1636. }
  1637. static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
  1638. void __user *buffer, size_t *lenp, loff_t *ppos,
  1639. int (*conv)(int *negp, unsigned long *lvalp, int *valp,
  1640. int write, void *data),
  1641. void *data)
  1642. {
  1643. return __do_proc_dointvec(table->data, table, write, filp,
  1644. buffer, lenp, ppos, conv, data);
  1645. }
  1646. /**
  1647. * proc_dointvec - read a vector of integers
  1648. * @table: the sysctl table
  1649. * @write: %TRUE if this is a write to the sysctl file
  1650. * @filp: the file structure
  1651. * @buffer: the user buffer
  1652. * @lenp: the size of the user buffer
  1653. * @ppos: file position
  1654. *
  1655. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1656. * values from/to the user buffer, treated as an ASCII string.
  1657. *
  1658. * Returns 0 on success.
  1659. */
  1660. int proc_dointvec(ctl_table *table, int write, struct file *filp,
  1661. void __user *buffer, size_t *lenp, loff_t *ppos)
  1662. {
  1663. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1664. NULL,NULL);
  1665. }
  1666. #define OP_SET 0
  1667. #define OP_AND 1
  1668. #define OP_OR 2
  1669. static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
  1670. int *valp,
  1671. int write, void *data)
  1672. {
  1673. int op = *(int *)data;
  1674. if (write) {
  1675. int val = *negp ? -*lvalp : *lvalp;
  1676. switch(op) {
  1677. case OP_SET: *valp = val; break;
  1678. case OP_AND: *valp &= val; break;
  1679. case OP_OR: *valp |= val; break;
  1680. }
  1681. } else {
  1682. int val = *valp;
  1683. if (val < 0) {
  1684. *negp = -1;
  1685. *lvalp = (unsigned long)-val;
  1686. } else {
  1687. *negp = 0;
  1688. *lvalp = (unsigned long)val;
  1689. }
  1690. }
  1691. return 0;
  1692. }
  1693. /*
  1694. * init may raise the set.
  1695. */
  1696. int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
  1697. void __user *buffer, size_t *lenp, loff_t *ppos)
  1698. {
  1699. int op;
  1700. if (write && !capable(CAP_SYS_MODULE)) {
  1701. return -EPERM;
  1702. }
  1703. op = is_init(current) ? OP_SET : OP_AND;
  1704. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1705. do_proc_dointvec_bset_conv,&op);
  1706. }
  1707. /*
  1708. * Taint values can only be increased
  1709. */
  1710. static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
  1711. void __user *buffer, size_t *lenp, loff_t *ppos)
  1712. {
  1713. int op;
  1714. if (write && !capable(CAP_SYS_ADMIN))
  1715. return -EPERM;
  1716. op = OP_OR;
  1717. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  1718. do_proc_dointvec_bset_conv,&op);
  1719. }
  1720. struct do_proc_dointvec_minmax_conv_param {
  1721. int *min;
  1722. int *max;
  1723. };
  1724. static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
  1725. int *valp,
  1726. int write, void *data)
  1727. {
  1728. struct do_proc_dointvec_minmax_conv_param *param = data;
  1729. if (write) {
  1730. int val = *negp ? -*lvalp : *lvalp;
  1731. if ((param->min && *param->min > val) ||
  1732. (param->max && *param->max < val))
  1733. return -EINVAL;
  1734. *valp = val;
  1735. } else {
  1736. int val = *valp;
  1737. if (val < 0) {
  1738. *negp = -1;
  1739. *lvalp = (unsigned long)-val;
  1740. } else {
  1741. *negp = 0;
  1742. *lvalp = (unsigned long)val;
  1743. }
  1744. }
  1745. return 0;
  1746. }
  1747. /**
  1748. * proc_dointvec_minmax - read a vector of integers with min/max values
  1749. * @table: the sysctl table
  1750. * @write: %TRUE if this is a write to the sysctl file
  1751. * @filp: the file structure
  1752. * @buffer: the user buffer
  1753. * @lenp: the size of the user buffer
  1754. * @ppos: file position
  1755. *
  1756. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  1757. * values from/to the user buffer, treated as an ASCII string.
  1758. *
  1759. * This routine will ensure the values are within the range specified by
  1760. * table->extra1 (min) and table->extra2 (max).
  1761. *
  1762. * Returns 0 on success.
  1763. */
  1764. int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
  1765. void __user *buffer, size_t *lenp, loff_t *ppos)
  1766. {
  1767. struct do_proc_dointvec_minmax_conv_param param = {
  1768. .min = (int *) table->extra1,
  1769. .max = (int *) table->extra2,
  1770. };
  1771. return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
  1772. do_proc_dointvec_minmax_conv, &param);
  1773. }
  1774. static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
  1775. struct file *filp,
  1776. void __user *buffer,
  1777. size_t *lenp, loff_t *ppos,
  1778. unsigned long convmul,
  1779. unsigned long convdiv)
  1780. {
  1781. #define TMPBUFLEN 21
  1782. unsigned long *i, *min, *max, val;
  1783. int vleft, first=1, neg;
  1784. size_t len, left;
  1785. char buf[TMPBUFLEN], *p;
  1786. char __user *s = buffer;
  1787. if (!data || !table->maxlen || !*lenp ||
  1788. (*ppos && !write)) {
  1789. *lenp = 0;
  1790. return 0;
  1791. }
  1792. i = (unsigned long *) data;
  1793. min = (unsigned long *) table->extra1;
  1794. max = (unsigned long *) table->extra2;
  1795. vleft = table->maxlen / sizeof(unsigned long);
  1796. left = *lenp;
  1797. for (; left && vleft--; i++, min++, max++, first=0) {
  1798. if (write) {
  1799. while (left) {
  1800. char c;
  1801. if (get_user(c, s))
  1802. return -EFAULT;
  1803. if (!isspace(c))
  1804. break;
  1805. left--;
  1806. s++;
  1807. }
  1808. if (!left)
  1809. break;
  1810. neg = 0;
  1811. len = left;
  1812. if (len > TMPBUFLEN-1)
  1813. len = TMPBUFLEN-1;
  1814. if (copy_from_user(buf, s, len))
  1815. return -EFAULT;
  1816. buf[len] = 0;
  1817. p = buf;
  1818. if (*p == '-' && left > 1) {
  1819. neg = 1;
  1820. p++;
  1821. }
  1822. if (*p < '0' || *p > '9')
  1823. break;
  1824. val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
  1825. len = p-buf;
  1826. if ((len < left) && *p && !isspace(*p))
  1827. break;
  1828. if (neg)
  1829. val = -val;
  1830. s += len;
  1831. left -= len;
  1832. if(neg)
  1833. continue;
  1834. if ((min && val < *min) || (max && val > *max))
  1835. continue;
  1836. *i = val;
  1837. } else {
  1838. p = buf;
  1839. if (!first)
  1840. *p++ = '\t';
  1841. sprintf(p, "%lu", convdiv * (*i) / convmul);
  1842. len = strlen(buf);
  1843. if (len > left)
  1844. len = left;
  1845. if(copy_to_user(s, buf, len))
  1846. return -EFAULT;
  1847. left -= len;
  1848. s += len;
  1849. }
  1850. }
  1851. if (!write && !first && left) {
  1852. if(put_user('\n', s))
  1853. return -EFAULT;
  1854. left--, s++;
  1855. }
  1856. if (write) {
  1857. while (left) {
  1858. char c;
  1859. if (get_user(c, s++))
  1860. return -EFAULT;
  1861. if (!isspace(c))
  1862. break;
  1863. left--;
  1864. }
  1865. }
  1866. if (write && first)
  1867. return -EINVAL;
  1868. *lenp -= left;
  1869. *ppos += *lenp;
  1870. return 0;
  1871. #undef TMPBUFLEN
  1872. }
  1873. static int do_proc_doulongvec_minmax(ctl_table *table, int write,
  1874. struct file *filp,
  1875. void __user *buffer,
  1876. size_t *lenp, loff_t *ppos,
  1877. unsigned long convmul,
  1878. unsigned long convdiv)
  1879. {
  1880. return __do_proc_doulongvec_minmax(table->data, table, write,
  1881. filp, buffer, lenp, ppos, convmul, convdiv);
  1882. }
  1883. /**
  1884. * proc_doulongvec_minmax - read a vector of long integers with min/max values
  1885. * @table: the sysctl table
  1886. * @write: %TRUE if this is a write to the sysctl file
  1887. * @filp: the file structure
  1888. * @buffer: the user buffer
  1889. * @lenp: the size of the user buffer
  1890. * @ppos: file position
  1891. *
  1892. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  1893. * values from/to the user buffer, treated as an ASCII string.
  1894. *
  1895. * This routine will ensure the values are within the range specified by
  1896. * table->extra1 (min) and table->extra2 (max).
  1897. *
  1898. * Returns 0 on success.
  1899. */
  1900. int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
  1901. void __user *buffer, size_t *lenp, loff_t *ppos)
  1902. {
  1903. return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
  1904. }
  1905. /**
  1906. * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
  1907. * @table: the sysctl table
  1908. * @write: %TRUE if this is a write to the sysctl file
  1909. * @filp: the file structure
  1910. * @buffer: the user buffer
  1911. * @lenp: the size of the user buffer
  1912. * @ppos: file position
  1913. *
  1914. * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
  1915. * values from/to the user buffer, treated as an ASCII string. The values
  1916. * are treated as milliseconds, and converted to jiffies when they are stored.
  1917. *
  1918. * This routine will ensure the values are within the range specified by
  1919. * table->extra1 (min) and table->extra2 (max).
  1920. *
  1921. * Returns 0 on success.
  1922. */
  1923. int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
  1924. struct file *filp,
  1925. void __user *buffer,
  1926. size_t *lenp, loff_t *ppos)
  1927. {
  1928. return do_proc_doulongvec_minmax(table, write, filp, buffer,
  1929. lenp, ppos, HZ, 1000l);
  1930. }
  1931. static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
  1932. int *valp,
  1933. int write, void *data)
  1934. {
  1935. if (write) {
  1936. if (*lvalp > LONG_MAX / HZ)
  1937. return 1;
  1938. *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
  1939. } else {
  1940. int val = *valp;
  1941. unsigned long lval;
  1942. if (val < 0) {
  1943. *negp = -1;
  1944. lval = (unsigned long)-val;
  1945. } else {
  1946. *negp = 0;
  1947. lval = (unsigned long)val;
  1948. }
  1949. *lvalp = lval / HZ;
  1950. }
  1951. return 0;
  1952. }
  1953. static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
  1954. int *valp,
  1955. int write, void *data)
  1956. {
  1957. if (write) {
  1958. if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
  1959. return 1;
  1960. *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
  1961. } else {
  1962. int val = *valp;
  1963. unsigned long lval;
  1964. if (val < 0) {
  1965. *negp = -1;
  1966. lval = (unsigned long)-val;
  1967. } else {
  1968. *negp = 0;
  1969. lval = (unsigned long)val;
  1970. }
  1971. *lvalp = jiffies_to_clock_t(lval);
  1972. }
  1973. return 0;
  1974. }
  1975. static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
  1976. int *valp,
  1977. int write, void *data)
  1978. {
  1979. if (write) {
  1980. *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
  1981. } else {
  1982. int val = *valp;
  1983. unsigned long lval;
  1984. if (val < 0) {
  1985. *negp = -1;
  1986. lval = (unsigned long)-val;
  1987. } else {
  1988. *negp = 0;
  1989. lval = (unsigned long)val;
  1990. }
  1991. *lvalp = jiffies_to_msecs(lval);
  1992. }
  1993. return 0;
  1994. }
  1995. /**
  1996. * proc_dointvec_jiffies - read a vector of integers as seconds
  1997. * @table: the sysctl table
  1998. * @write: %TRUE if this is a write to the sysctl file
  1999. * @filp: the file structure
  2000. * @buffer: the user buffer
  2001. * @lenp: the size of the user buffer
  2002. * @ppos: file position
  2003. *
  2004. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2005. * values from/to the user buffer, treated as an ASCII string.
  2006. * The values read are assumed to be in seconds, and are converted into
  2007. * jiffies.
  2008. *
  2009. * Returns 0 on success.
  2010. */
  2011. int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
  2012. void __user *buffer, size_t *lenp, loff_t *ppos)
  2013. {
  2014. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  2015. do_proc_dointvec_jiffies_conv,NULL);
  2016. }
  2017. /**
  2018. * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
  2019. * @table: the sysctl table
  2020. * @write: %TRUE if this is a write to the sysctl file
  2021. * @filp: the file structure
  2022. * @buffer: the user buffer
  2023. * @lenp: the size of the user buffer
  2024. * @ppos: pointer to the file position
  2025. *
  2026. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2027. * values from/to the user buffer, treated as an ASCII string.
  2028. * The values read are assumed to be in 1/USER_HZ seconds, and
  2029. * are converted into jiffies.
  2030. *
  2031. * Returns 0 on success.
  2032. */
  2033. int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
  2034. void __user *buffer, size_t *lenp, loff_t *ppos)
  2035. {
  2036. return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
  2037. do_proc_dointvec_userhz_jiffies_conv,NULL);
  2038. }
  2039. /**
  2040. * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
  2041. * @table: the sysctl table
  2042. * @write: %TRUE if this is a write to the sysctl file
  2043. * @filp: the file structure
  2044. * @buffer: the user buffer
  2045. * @lenp: the size of the user buffer
  2046. * @ppos: file position
  2047. * @ppos: the current position in the file
  2048. *
  2049. * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
  2050. * values from/to the user buffer, treated as an ASCII string.
  2051. * The values read are assumed to be in 1/1000 seconds, and
  2052. * are converted into jiffies.
  2053. *
  2054. * Returns 0 on success.
  2055. */
  2056. int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
  2057. void __user *buffer, size_t *lenp, loff_t *ppos)
  2058. {
  2059. return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
  2060. do_proc_dointvec_ms_jiffies_conv, NULL);
  2061. }
  2062. static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
  2063. void __user *buffer, size_t *lenp, loff_t *ppos)
  2064. {
  2065. struct pid *new_pid;
  2066. pid_t tmp;
  2067. int r;
  2068. tmp = pid_nr(cad_pid);
  2069. r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
  2070. lenp, ppos, NULL, NULL);
  2071. if (r || !write)
  2072. return r;
  2073. new_pid = find_get_pid(tmp);
  2074. if (!new_pid)
  2075. return -ESRCH;
  2076. put_pid(xchg(&cad_pid, new_pid));
  2077. return 0;
  2078. }
  2079. #else /* CONFIG_PROC_FS */
  2080. int proc_dostring(ctl_table *table, int write, struct file *filp,
  2081. void __user *buffer, size_t *lenp, loff_t *ppos)
  2082. {
  2083. return -ENOSYS;
  2084. }
  2085. int proc_dointvec(ctl_table *table, int write, struct file *filp,
  2086. void __user *buffer, size_t *lenp, loff_t *ppos)
  2087. {
  2088. return -ENOSYS;
  2089. }
  2090. int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
  2091. void __user *buffer, size_t *lenp, loff_t *ppos)
  2092. {
  2093. return -ENOSYS;
  2094. }
  2095. int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
  2096. void __user *buffer, size_t *lenp, loff_t *ppos)
  2097. {
  2098. return -ENOSYS;
  2099. }
  2100. int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
  2101. void __user *buffer, size_t *lenp, loff_t *ppos)
  2102. {
  2103. return -ENOSYS;
  2104. }
  2105. int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
  2106. void __user *buffer, size_t *lenp, loff_t *ppos)
  2107. {
  2108. return -ENOSYS;
  2109. }
  2110. int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
  2111. void __user *buffer, size_t *lenp, loff_t *ppos)
  2112. {
  2113. return -ENOSYS;
  2114. }
  2115. int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
  2116. void __user *buffer, size_t *lenp, loff_t *ppos)
  2117. {
  2118. return -ENOSYS;
  2119. }
  2120. int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
  2121. struct file *filp,
  2122. void __user *buffer,
  2123. size_t *lenp, loff_t *ppos)
  2124. {
  2125. return -ENOSYS;
  2126. }
  2127. #endif /* CONFIG_PROC_FS */
  2128. #ifdef CONFIG_SYSCTL_SYSCALL
  2129. /*
  2130. * General sysctl support routines
  2131. */
  2132. /* The generic string strategy routine: */
  2133. int sysctl_string(ctl_table *table, int __user *name, int nlen,
  2134. void __user *oldval, size_t __user *oldlenp,
  2135. void __user *newval, size_t newlen)
  2136. {
  2137. if (!table->data || !table->maxlen)
  2138. return -ENOTDIR;
  2139. if (oldval && oldlenp) {
  2140. size_t bufsize;
  2141. if (get_user(bufsize, oldlenp))
  2142. return -EFAULT;
  2143. if (bufsize) {
  2144. size_t len = strlen(table->data), copied;
  2145. /* This shouldn't trigger for a well-formed sysctl */
  2146. if (len > table->maxlen)
  2147. len = table->maxlen;
  2148. /* Copy up to a max of bufsize-1 bytes of the string */
  2149. copied = (len >= bufsize) ? bufsize - 1 : len;
  2150. if (copy_to_user(oldval, table->data, copied) ||
  2151. put_user(0, (char __user *)(oldval + copied)))
  2152. return -EFAULT;
  2153. if (put_user(len, oldlenp))
  2154. return -EFAULT;
  2155. }
  2156. }
  2157. if (newval && newlen) {
  2158. size_t len = newlen;
  2159. if (len > table->maxlen)
  2160. len = table->maxlen;
  2161. if(copy_from_user(table->data, newval, len))
  2162. return -EFAULT;
  2163. if (len == table->maxlen)
  2164. len--;
  2165. ((char *) table->data)[len] = 0;
  2166. }
  2167. return 1;
  2168. }
  2169. /*
  2170. * This function makes sure that all of the integers in the vector
  2171. * are between the minimum and maximum values given in the arrays
  2172. * table->extra1 and table->extra2, respectively.
  2173. */
  2174. int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
  2175. void __user *oldval, size_t __user *oldlenp,
  2176. void __user *newval, size_t newlen)
  2177. {
  2178. if (newval && newlen) {
  2179. int __user *vec = (int __user *) newval;
  2180. int *min = (int *) table->extra1;
  2181. int *max = (int *) table->extra2;
  2182. size_t length;
  2183. int i;
  2184. if (newlen % sizeof(int) != 0)
  2185. return -EINVAL;
  2186. if (!table->extra1 && !table->extra2)
  2187. return 0;
  2188. if (newlen > table->maxlen)
  2189. newlen = table->maxlen;
  2190. length = newlen / sizeof(int);
  2191. for (i = 0; i < length; i++) {
  2192. int value;
  2193. if (get_user(value, vec + i))
  2194. return -EFAULT;
  2195. if (min && value < min[i])
  2196. return -EINVAL;
  2197. if (max && value > max[i])
  2198. return -EINVAL;
  2199. }
  2200. }
  2201. return 0;
  2202. }
  2203. /* Strategy function to convert jiffies to seconds */
  2204. int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
  2205. void __user *oldval, size_t __user *oldlenp,
  2206. void __user *newval, size_t newlen)
  2207. {
  2208. if (oldval && oldlenp) {
  2209. size_t olen;
  2210. if (get_user(olen, oldlenp))
  2211. return -EFAULT;
  2212. if (olen) {
  2213. int val;
  2214. if (olen < sizeof(int))
  2215. return -EINVAL;
  2216. val = *(int *)(table->data) / HZ;
  2217. if (put_user(val, (int __user *)oldval))
  2218. return -EFAULT;
  2219. if (put_user(sizeof(int), oldlenp))
  2220. return -EFAULT;
  2221. }
  2222. }
  2223. if (newval && newlen) {
  2224. int new;
  2225. if (newlen != sizeof(int))
  2226. return -EINVAL;
  2227. if (get_user(new, (int __user *)newval))
  2228. return -EFAULT;
  2229. *(int *)(table->data) = new*HZ;
  2230. }
  2231. return 1;
  2232. }
  2233. /* Strategy function to convert jiffies to seconds */
  2234. int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
  2235. void __user *oldval, size_t __user *oldlenp,
  2236. void __user *newval, size_t newlen)
  2237. {
  2238. if (oldval && oldlenp) {
  2239. size_t olen;
  2240. if (get_user(olen, oldlenp))
  2241. return -EFAULT;
  2242. if (olen) {
  2243. int val;
  2244. if (olen < sizeof(int))
  2245. return -EINVAL;
  2246. val = jiffies_to_msecs(*(int *)(table->data));
  2247. if (put_user(val, (int __user *)oldval))
  2248. return -EFAULT;
  2249. if (put_user(sizeof(int), oldlenp))
  2250. return -EFAULT;
  2251. }
  2252. }
  2253. if (newval && newlen) {
  2254. int new;
  2255. if (newlen != sizeof(int))
  2256. return -EINVAL;
  2257. if (get_user(new, (int __user *)newval))
  2258. return -EFAULT;
  2259. *(int *)(table->data) = msecs_to_jiffies(new);
  2260. }
  2261. return 1;
  2262. }
  2263. #else /* CONFIG_SYSCTL_SYSCALL */
  2264. asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
  2265. {
  2266. static int msg_count;
  2267. struct __sysctl_args tmp;
  2268. int name[CTL_MAXNAME];
  2269. int i;
  2270. /* Read in the sysctl name for better debug message logging */
  2271. if (copy_from_user(&tmp, args, sizeof(tmp)))
  2272. return -EFAULT;
  2273. if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
  2274. return -ENOTDIR;
  2275. for (i = 0; i < tmp.nlen; i++)
  2276. if (get_user(name[i], tmp.name + i))
  2277. return -EFAULT;
  2278. /* Ignore accesses to kernel.version */
  2279. if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
  2280. goto out;
  2281. if (msg_count < 5) {
  2282. msg_count++;
  2283. printk(KERN_INFO
  2284. "warning: process `%s' used the removed sysctl "
  2285. "system call with ", current->comm);
  2286. for (i = 0; i < tmp.nlen; i++)
  2287. printk("%d.", name[i]);
  2288. printk("\n");
  2289. }
  2290. out:
  2291. return -ENOSYS;
  2292. }
  2293. int sysctl_string(ctl_table *table, int __user *name, int nlen,
  2294. void __user *oldval, size_t __user *oldlenp,
  2295. void __user *newval, size_t newlen)
  2296. {
  2297. return -ENOSYS;
  2298. }
  2299. int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
  2300. void __user *oldval, size_t __user *oldlenp,
  2301. void __user *newval, size_t newlen)
  2302. {
  2303. return -ENOSYS;
  2304. }
  2305. int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
  2306. void __user *oldval, size_t __user *oldlenp,
  2307. void __user *newval, size_t newlen)
  2308. {
  2309. return -ENOSYS;
  2310. }
  2311. int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
  2312. void __user *oldval, size_t __user *oldlenp,
  2313. void __user *newval, size_t newlen)
  2314. {
  2315. return -ENOSYS;
  2316. }
  2317. #endif /* CONFIG_SYSCTL_SYSCALL */
  2318. /*
  2319. * No sense putting this after each symbol definition, twice,
  2320. * exception granted :-)
  2321. */
  2322. EXPORT_SYMBOL(proc_dointvec);
  2323. EXPORT_SYMBOL(proc_dointvec_jiffies);
  2324. EXPORT_SYMBOL(proc_dointvec_minmax);
  2325. EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
  2326. EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
  2327. EXPORT_SYMBOL(proc_dostring);
  2328. EXPORT_SYMBOL(proc_doulongvec_minmax);
  2329. EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
  2330. EXPORT_SYMBOL(register_sysctl_table);
  2331. EXPORT_SYMBOL(sysctl_intvec);
  2332. EXPORT_SYMBOL(sysctl_jiffies);
  2333. EXPORT_SYMBOL(sysctl_ms_jiffies);
  2334. EXPORT_SYMBOL(sysctl_string);
  2335. EXPORT_SYMBOL(unregister_sysctl_table);