sysctl.c 69 KB

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