sysctl.c 68 KB

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