sysctl.c 68 KB

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