sysctl.c 67 KB

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