sysctl.c 68 KB

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