sysctl.c 59 KB

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