sysctl.c 71 KB

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