sysctl.c 68 KB

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