sysctl.c 68 KB

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