sysctl.c 67 KB

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