sysctl.c 68 KB

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