sysctl.c 71 KB

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