sysctl.c 71 KB

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