sysctl.c 69 KB

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