sysctl.c 68 KB

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