sysctl.c 69 KB

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