sysctl.c 69 KB

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