sysctl.c 71 KB

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