sysctl.c 68 KB

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