sysctl.c 67 KB

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