sysctl.c 69 KB

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