sysctl.c 68 KB

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